parallel-future
v0.0.6
Published
Run Futures in parallel
Downloads
6
Maintainers
Readme
parallel-future
Run Futures in parallel
Example
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.
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:
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