iter

Serial & Parallel Iteration

npm install iter
24 downloads in the last week
50 downloads in the last month

Serial & Parallel Iteration

Install

npm install iter

Usage

iter(20, function(next, i){ /* or: iter(0, 20, .. */
  console.log('i: %d', i);
  next();
});

Callbacks;

iter(20)
  .error(function(error){ throw error; })
  .done(function(){ console.log('done'); })
  .run(function(next, i){
    console.log('i: %d', i);
    next(); // to pass an error: next(new Error('failed!'))
  });

Parallel

It's serial by default. Use parallel method to make it parallel.

iter.parallel(5, function (done, i) {
  setTimeout(function () {
    console.log(i)
    done()
  }, 1000 - (i * 200))
})

Will output:

4
3
2
1
0
npm loves you