https://github.com/futurize/parallel-future
Run Futures in parallel
https://github.com/futurize/parallel-future
Last synced: about 1 month ago
JSON representation
Run Futures in parallel
- Host: GitHub
- URL: https://github.com/futurize/parallel-future
- Owner: futurize
- License: mit
- Created: 2016-02-28T14:12:36.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-03-05T11:37:10.000Z (almost 10 years ago)
- Last Synced: 2025-08-09T12:57:30.234Z (6 months ago)
- Language: JavaScript
- Homepage:
- Size: 14.6 KB
- Stars: 7
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-functional-programming - **parallel-future** - Run Futures in parallel
- awesome-functional-programming - **parallel-future** - Run Futures in parallel
README
parallel-future
===============
[](https://travis-ci.org/futurize/parallel-future)
[](https://www.npmjs.com/package/parallel-future)
[](https://codecov.io/github/futurize/parallel-future?branch=master)
> Run Futures in parallel
## Example
```js
const Task = require('data.task');
const parallel = require('parallel-future')(Task);
const parallelRequests = parallel([ getUsers, getPosts ]);
parallelRequests.fork(onRejected, (results) => {
console.log('Users', results[0]);
console.log('Posts', results[1]);
});
```
## Why not `R.sequence(Task.of)`?
Because it only appears to run the `Futures` in parallel.
Run the tests and see for your self.
```js
describe('runs parallel', () => {
it('should run Futures in parallel', done => {
console.time('parallel-future');
parallel([ time(1)
, time(2)
, time(3)
]).fork(_, eventuallyEqual([1, 2, 3], () => { console.timeEnd('parallel-future'); done() }));
});
it('compared to R.sequence (only appears to be parallel)', done => {
console.time('sequence');
R.sequence(Task.of)
([ time(1)
, time(2)
, time(3)
]).fork(_, eventuallyEqual([1, 2, 3], () => { console.timeEnd('sequence'); done() }));
});
});
```
Output:
```bash
runs parallel
parallel-future: 106ms
✓ should run Futures in parallel (106ms)
sequence: 315ms
✓ compared to R.sequence (only appears to be parallel) (316ms)
```
## API
### `parallelFuture :: Future -> [Future a] -> Future [a]`
## License
MIT © [stoeffel](https://stoeffel.github.io)