node-parallel

Parallel provide a simple way for management of parrallel async/sync call

Parallel

Parallel provide a simple way for management of parallel async call, you can remember the API just by a glance.

Normally we use async or promise for parallel async control. They can resolve every kind of async control problem we get, but the problem is they've done too much and it's neither easy to remember the complicated APIs nor refactoring the code.

For node:

npm install node-parallel

As component:

component install chemzqm/parallel
var parallel = new Parallel();
parallel.timeout(3000);
for (var i = 0; i < 3; i++) {
  parallel.add(function(done){
    request.get('/user/' + i, function(errres) {
      done(err, res.body.name);
    })
  })
}
parallel.done(function(errresults) {
  if (err) throw err;
  // results => ["jack", "tony", "fat"]; 
});

Init new Parallel instance.

Set the timeout to number ms, default is 10s.

Add Function to parallel, the first argument is a callback function, it should be called with error as first argument and result you need as secound argument.

The callback function is called with error (null or undefined if not exist) and the result array when all the request get finished (or timeout reached).

Note, this function should only be called once.

MIT