co-gather
Execute thunks in parallel with concurrency support and gather all the results
Last updated 4 years ago by dead_horse .
MIT · Repository · Bugs · Original npm · Tarball
$ cnpm install co-gather 
SYNC missed versions from official npm registry.

co-gather

Execute thunks in parallel with concurrency support and gather all the results.

co-gather is similar with co-parallel, but co-gather will gather all the result of these thunks, even those thunks throw error.

Installation

$ npm install co-gather

Example

var gather = require('co-gather');
var thread = require('co-thread');
var wait = require('co-wait');
var co = require('co');

var index = 0;
function *random() {
  var i = index++;
  yield wait(Math.random() * 100);
  if (Math.random() > 0.5) {
    throw new Error('error');
  }
  return i;
}

co(function *() {
  var ret = yield gather(thread(random, 10));
  console.log(ret);
})();

=>

[
  { isError: true, error: [Error: error] },
  { isError: true, error: [Error: error] },
  { isError: true, error: [Error: error] },
  { isError: true, error: [Error: error] },
  { isError: true, error: [Error: error] },
  { isError: false, value: 5 },
  { isError: false, value: 6 },
  { isError: false, value: 7 },
  { isError: true, error: [Error: error] },
  { isError: true, error: [Error: error] }
]

API

gather(thunks, [concurrency])

Execute thunks in parallel, with the given concurrency defaulting to 5, and gather the result

License

MIT

Maintainers (1)
Downloads
Today 13
This Week 1,063
This Month 3,729
Last Day 49
Last Week 1,051
Last Month 5,487
Dependencies (1)
Dev Dependencies (2)

Copyright 2014 - 2017 © taobao.org |