1.2.0 • Published 8 years ago
gw2e-async-promises v1.2.0
async-promises
Wrapping promises with the async library. This enables you to pass promise-generating functions to the
parallel
andseries
methods and returns a promise instead of having to specify a callback
This is part of gw2efficiency. Please report all issues in the central repository.
Install
npm install gw2e-async-promises
This module can be used for Node.js as well as browsers using Browserify.
Usage
const async = require('gw2e-async-promises')
// 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.')),
// ...
]
// Await
let results = await async.parallel(promiseArray)
let results = await async.parallel(promiseArray, limitOfParallelTasks)
let results = await async.parallel(promiseArray, limitOfParallelTasks, boolSilenceErrors)
let results = await async.series(promiseArray)
let results = await async.series(promiseArray, boolSilenceErrors)
// Promises
async.parallel(promiseArray).then(results => console.log(results))
async.parallel(promiseArray, limitOfParallelTasks).then(results => console.log(results))
async.parallel(promiseArray, limitOfParallelTasks, boolSilenceErrors).then(results => console.log(results))
async.series(promiseArray).then(results => console.log(results))
async.series(promiseArray, boolSilenceErrors).then(results => console.log(results))
Tests
npm test
Licence
MIT