1.2.1 • Published 8 years ago
promise-flowcontrol v1.2.1
promise-flowcontrol
Wrapping the async library to support working with promises. This enables you to pass promise-generating functions to the
parallel
andseries
methods and returns a promise instead of having to specify a callback
Install
npm install promise-flowcontrol
This module can be used for Node.js as well as browsers using Browserify.
Usage
Basic usage
import async from 'promise-flowcontrol'
// 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
async.parallel(promiseArray)
.then(results => console.log(results))
// Work on the promises in series
async.series(promiseArray)
.then(results => console.log(results))
API
- parallel(tasks, limit, silenceErrors)
tasks
- List of promise-returning functionslimit
- Optional concurrency limitsilenceErrors
- If optionally set totrue
, ignore errors in the promises and returnnull
for failed promises instead
- series(tasks, silenceErrors)
tasks
- List of promise-returning functionssilenceErrors
- If optionally set totrue
, ignore errors in the promises and returnnull
for failed promises instead
Tests
npm test
Licence
MIT
1.2.1
8 years ago