Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Chained and parallel async iterator in one elegant function
CoffeeScript JavaScript

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
doc
lib
samples
src
test
.gitignore
.travis.yml
LICENSE
README.md
index.js
package.json

README.md

Build Status

 _   _           _        ______           _     
| \ | |         | |      |  ____|         | |    
|  \| | ___   __| | ___  | |__   __ _  ___| |__  
| . ` |/ _ \ / _` |/ _ \ |  __| / _` |/ __| '_ \ 
| |\  | (_) | (_| |  __/ | |___| (_| | (__| | | |
|_| \_|\___/ \__,_|\___| |______\__,_|\___|_| |_| New BSD License

Full documentation for the Each is available here.

Note, for user of versions 0.2.x and below, arguments of the item callback have changed. See the documentation for additionnal information.

Node Each is a single elegant function to iterate asynchronously over elements both in sequential, parallel and concurrent mode.

Example using the promise API

each( [{id: 1}, {id: 2}, {id: 3}] )
.run( function(element, index, next){
  console.log('element: ', element, '@', index);
  setTimeout(next, 500);
})
.then( function(err){
  console.log(err ? err.message : 'Done');
});

Example using the event API

This is the same code as above using a different API.

var each = require('each');
each( [{id: 1}, {id: 2}, {id: 3}] )
.on('item', function(element, index, next) {
  console.log('element: ', element, '@', index);
  setTimeout(next, 500);
})
.on('error', function(err) {
  console.log(err.message);
})
.on('end', function() {
  console.log('Done');
});

Development

Node Each comes with a few example, all present in the "samples" folder. Here's how you may run each of them :

node samples/array_concurrent.js
node samples/array_parallel.js
node samples/array_sequential.js
node samples/object_concurrent.js
node samples/object_sequential.js
node samples/readable_stream.js

Tests are executed with mocha. To install it, simple run npm install, it will install mocha and its dependencies in your project "node_modules" directory.

make test
Something went wrong with that request. Please try again.