A simple queue that batches items together and releases them periodically. Useful for processing large sets of data in batches.
To install the library using npm, run:
npm install @jakguru/bucketqueue
The library can be used with both TypeScript and CommonJS. Here are some examples of how to use it:
import BucketQueue from '@jakguru/bucketqueue';
const queue = new BucketQueue<string>({
interval: 1000,
maxBatch: 100,
minBatch: 10,
onSpill: (items) => {
console.log(`Spilled ${items.length} items`);
},
});
queue.push('item 1');
queue.push('item 2');
queue.push('item 3');
const BucketQueue = require('@jakguru/bucketqueue').default;
const queue = new BucketQueue({
interval: 1000,
maxBatch: 100,
minBatch: 10,
onSpill: (items) => {
console.log(`Spilled ${items.length} items`);
},
});
queue.push('item 1');
queue.push('item 2');
queue.push('item 3');
For full API documentation, see TypeDoc Documentation
The following properties, methods and events are available:
options: BucketQueueOptionsReturns the options object used to create the queue.
pressure: numberReturns the number of items in the queue.
push(...items: T[])Adds one or more items to the queue.
add(...items: T[])Alias for push.
enqueue(...items: T[])Alias for push.
start(): voidStarts the queue.
stop(): voidStops the queue.
pause(): voidPauses the queue.
resume(): voidResumes the queue.
remove(item: T): voidRemoves an item from the queue.
dequeue(item: T): voidAlias for remove.
on(event: string, listener: Function): voidAdds a listener to an event. The following events are available:
tickspillspilleddrainfinisherrorpipeunpipecorkeduncorkedIf you would like to contribute to this project, feel free to open a pull request or an issue on the GitHub repository. All contributions are welcome!
Generated using TypeDoc