A simple promise and event based async queue.
const Q = require('simple-async-q')
function fn () {
return new Promise(async (resolve, reject) => {
// some async stuff
})
}
const q = new Q(fn)
q.add('test')
q.add('Test')
q.start()
The provided function has to return a Promise.
Start the queue.
Pause the queue. The queue will be paused after the currently running task has finished.
Resume the queue.
Kill the queue(remove all added tasks). The queue will be killed after the currently running task has finished.
Is triggered when a task is finished. If no error occured then err is null. Value has 2 attributes: value which holds the resolved value from the function and payload which is the value added on q.add.
q.on('finished', (err, value) => {
})
Is triggered when all tasks have been finished.
q.on('all-finished', () => {
})
Is triggered when an general error occurs. This event is not triggered when an error occurs inside the task function.
q.on('error', err => {
})
MIT © sys0