futurist
v0.0.3
Published
Execute promises with limited parallelism
Downloads
3
Readme
Futurist
Futurist helps executing promises with limited parallelism.
Install
# If you are using npm
npm install futurist
# If you are using yarn
yarn add futurist
Usage
const Futurist = require('futurist');
const futurist = new Futurist(2, 10000);
futurist.execute(() => fetch('http://example.com'))
.then(console.log)
.catch(console.error);
API
new Futurist(maxPendingPromises, timeout)
Create a new Futurist instance to execute promises.
Parameters
maxPendingPromises: Number
: Optional. Number of maximum parallel pending promises at any time (default:5
).timeout: Number
: Optional. Timeout in ms before a request is rejected (default:30000
). The timeout at the time of promise execution, not when adding a promise.
Returns
The Futurist instance
futurist.execute(promiseCreator)
Add a new promise creator to be executed as soon as possible.
Parameters
promiseCreator: Function
: A function that returns thePromise
to be executed.
Returns
A Promise
that is resolved/rejected when the Promise returned by promiseCreator
is resolved/rejected or rejected when resolution takes longer than the defined timeout.