Created
May 21, 2013 17:45
-
-
Save tmcw/5621737 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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