A queue with a limited amount of slots.
npm i limited-queue
// Import the library.
import LimitedQueue from "@voidvoxel/limited-queue";
// Create a new queue with a capacity of 3.
const queue = new LimitedQueue(3);
// Push 5 values.
queue.push(1, 2, 3, 4, 5);
// Log the queue's contents.
console.log(queue);
// Expected output:
// LimitedQueue(3) [ 3, 4, 5 ]
// Import the library.
import LimitedQueue from "@voidvoxel/limited-queue";
const extras = [];
class OverflowQueue extends LimitedQueue {
_overflow (value) {
extras.push(value);
}
}
// Create a new queue with a capacity of 3.
const queue = new OverflowQueue(3);
// Push 5 values.
queue.push(1, 2, 3, 4, 5);
// Log the queue's contents.
console.log(extras);
// Expected output:
// [ 1, 2 ]