https://github.com/bfncs/futurist
Execute promises with limited parallelism
https://github.com/bfncs/futurist
promises
Last synced: 10 months ago
JSON representation
Execute promises with limited parallelism
- Host: GitHub
- URL: https://github.com/bfncs/futurist
- Owner: bfncs
- Created: 2017-08-22T17:17:27.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-08-22T18:31:33.000Z (almost 9 years ago)
- Last Synced: 2025-07-22T12:54:39.519Z (11 months ago)
- Topics: promises
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/futurist
- Size: 30.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Futurist
[](https://travis-ci.org/bfncs/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
```js
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
1. `maxPendingPromises: Number`: Optional. Number of maximum parallel pending promises at any time (default: `5`).
2. `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
1. `promiseCreator: Function`: A function that returns the `Promise` 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.