Skip to content

Simple automatic, dynamic callback queue for node.

License

Notifications You must be signed in to change notification settings

kyleaedwards/autoq

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

autoq

Simple automatic, dynamic callback queue for node.

NPM Version NPM Downloads

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)
    }

})

License

MIT

About

Simple automatic, dynamic callback queue for node.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published