Skip to content

Instantly share code, notes, and snippets.

@cschep
Created April 23, 2015 21:38
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 cschep/841dd3f4e274e75d4d34 to your computer and use it in GitHub Desktop.
Save cschep/841dd3f4e274e75d4d34 to your computer and use it in GitHub Desktop.
var asyncMap = function(tasks, callback){
var results = [];
var tasksCompleted = 0;
var makeCallBack = function(i) {
return function(x) {
results[i] = x;
tasksCompleted++;
if (tasksCompleted === tasks.length) {
callback(results);
}
}
};
for (var i = 0; i < tasks.length; i++) {
tasks[i](makeCallBack(i));
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment