Skip to content

Instantly share code, notes, and snippets.

@tmcw
Created May 21, 2013 17:45
Show Gist options
  • 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