Skip to content

queicherius/promise-control-flow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

promise-control-flow

Build Status Coverage Status Greenkeeper badge

Wrapping the contra library to support working with promises. This enables you to pass promise-generating functions to the parallel and series methods and returns a promise instead of having to specify a callback

Install

npm install promise-control-flow

This module can be used for Node.js as well as browsers using Browserify.

Usage

Basic usage

const flow = require('promise-control-flow')

// Note: promisesArray expects to be built out of *functions*
// that return promises, because else the promises start 
// instantly and can't be run in series anymore.
let promiseArray = [
  () => new Promise(resolve => resolve('Test.')),
  // ...
]

// Work on all promises in parallel
flow.parallel(promiseArray)
  .then(results => console.log(results))

// Work on the promises in series
flow.series(promiseArray)
  .then(results => console.log(results))

API

  • parallel(tasks, [limit], [silenceErrors])
    • tasks - List of promise-returning functions
    • limit - Optional concurrency limit
    • silenceErrors - If optionally set to true, ignore errors in the promises and return null for failed promises instead
  • series(tasks, [silenceErrors])
    • tasks - List of promise-returning functions
    • silenceErrors - If optionally set to true, ignore errors in the promises and return null for failed promises instead

Tests

npm test

Licence

MIT

About

Wrapping the contra library to support promises (parallel/series)

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published