autoq
v0.3.2
Published
Automatic, dynamic callback queue
Downloads
2
Maintainers
Readme
autoq
Simple automatic, dynamic callback queue for node.
AutoQ lets you chain functions as you need to create them, without needing to juggle Promise objects manually. The main benefit is that you can provide a running asynchronous function with a callback you're generating dynamically (possibly in another asynchronous function).
Installation
$ npm install autoq
Usage
const AutoQ = require('autoq')
const autoq = new AutoQ((err) => {
console.log('Error during autoq: ', err)
})
autoq.add((arg, next) => {
// Do something asynchronous.
setTimeout(function () {
console.log(arg) // null
// Pass an argument to the next iteration.
next(5)
}, 500)
})
autoq.add((arg, next) => {
console.log(arg) // 5
if (arg === 5) {
// Will be caught by error handler provided
// by the constructor.
throw "I don't like the number 5."
} else {
setTimeout(function () {
next(arg + 1)
}, 500)
}
})