This package has been deprecated

Author message:

Development of this module has been stopped.

funq

4.0.3 • Public • Published

funq

Greenkeeper badge NPM version Build status License Code style

A simple asynchronous function queue, executing either sequentially or in parallel.

Installation

$ npm install funq --save

...or:

$ yarn add funq

Usage

Create a new instance of Funq(). Each object will have a push() method, taking a callback as an argument and sequential() and parallel() methods to kick the whole process off. The constructor function takes a completion callback with an error value which will either contain an error object/string, etc.. or be null if no errors were passed back, this is called once the whole chain of functions have finished.

If parallel() is used, then all functions pushed to the instance will run immediately and the completion callback will be called once the slowest function has finished, otherwise, using sequential() everything will run in order and take as long as all the functions take to complete. Also you can optionally pass a value back (i.e. done([value])) which will complete the sequence early.

Example:

const Funq = require('funq')
 
const queue = new Funq((err, value) => {
  if (err) return console.log(err) // an error was passed back and the sequence ended early
  // otherwise do stuff after sequence is fully completed
})
 
queue.push((fail, done) => {
  // do some async work and either fail with an error
  // or mark successfull with done
 
  // optionally pass a value back, this also has the effect
  // or completing the sequence early
  done({pass: 'value back'})
})
 
queue.push((fail, done) => {
  fail(new Error('an error occurred'))
})
 
queue.push((fail, done) => {
  // won't be called because error was passed back
})
 
queue.sequential() // or `.parallel()`

Browsers

Use browserify or similar.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Published

Version History

  • Version
    Downloads (Last 7 Days)
    • Published

Package Sidebar

Install

npm i funq

Weekly Downloads

11

Version

4.0.3

License

MIT

Last publish

Collaborators

  • roryrjb