Skip to content

Instantly share code, notes, and snippets.

@tmcw
Created May 21, 2013 17:45
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 tmcw/5621737 to your computer and use it in GitHub Desktop.
Save tmcw/5621737 to your computer and use it in GitHub Desktop.
function asyncMap(inputs, func, callback) {
var remaining = inputs.length,
results = [],
errors = [];
inputs.forEach(function(d, i) {
func(d, function done(err, data) {
errors[i] = err;
results[i] = data;
remaining --;
if (!remaining) callback(errors, results);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment