Serial & Parallel Iteration
JavaScript
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
.gitignore
README.md
index.js
package.json
test.js

README.md

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