Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    parallel-futurepublic

    parallel-future

    build status npm version codecov.io

    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

    install

    npm i parallel-future

    Downloadsweekly downloads

    27

    version

    0.0.6

    license

    MIT

    repository

    githubgithub

    last publish

    collaborators

    • avatar