Skip to content

Instantly share code, notes, and snippets.

@yawnt
Created August 19, 2012 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yawnt/3397183 to your computer and use it in GitHub Desktop.
Save yawnt/3397183 to your computer and use it in GitHub Desktop.
async ee
var Emitter = require('events').EventEmitter;
exports.async = function(arr, fn, done) {
var todo = arr.length,
em = new Emitter();
em.on('done', function() {
if(!(--todo)) { done(); }
});
arr.forEach(function(item) {
fn(item, em);
});
};
/*
example:
utile.async([1,2,3], function(item, em) {
Math.sin(item);
em.emit('done');
}, function() { console.log('done'); });
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment