npm install easy-queue-ks
commonJS:
const EzQueue = require('eazy-queue-ks');
es2015:
import EzQueue from 'eazy-queue-ks';
- Easily add items to the queue.
- Asynchronously process the items with a customizable callback function.
- Events for queue progress tracking.
-
job
: Triggered when the queue starts processing. -
done
: Triggered when a job is done. -
complete
: Triggered when the entire queue is completed.
-
Name | Default | Description |
---|---|---|
T |
- | Type that is pushed onto the stack. |
Add an item to the queue. You can pass a single item or an array of items.
Start processing the queue with the provided callback function. The callback function should return true for 'done' and false for 'finish' events.
Get the current number of items in the queue.
job: Triggered when the queue starts processing.
done: Triggered when a job is done (returns true).
complete: Triggered when the entire queue is completed.
import EzQueue from 'eazy-queue-ks';
const ezq = new EzQueue();
ezq.on('job', () => {
ezq.process(async (job) => {
await somethingAsync();
// ...TODO
return `ok ${job}`; // Not require return
});
});
ezq.add([1, 2, 3, 4]);
ezq.add(5);
ezq.on('complete', () => {
// all job is done
console.log('complete');
});
ezq.on('done', (result, job) => {
// if ezq.process is return ezq.process example 'ok 1', 'ok 2'
// job is data of process example 1, 2 ,3
console.log('done', result, job);
});
If you encounter any issues or have suggestions for improvements, please open an issue on the GitHub repository.