Skip to content

Instantly share code, notes, and snippets.

@pietrom
Last active September 8, 2016 13:41
Show Gist options
  • Save pietrom/8d8171668a8703f36ce9ab83d669ff64 to your computer and use it in GitHub Desktop.
Save pietrom/8d8171668a8703f36ce9ab83d669ff64 to your computer and use it in GitHub Desktop.
function after(times, callback) {
return function() {
times--;
if(times === 0) {
callback();
}
}
}
function asyncmap(list, op, cb) {
var results = []
var error = null;
var done = after(list.length, function() {
cb(error, results);
});
list.forEach(function(item, i) {
op(item, function(err, result) {
if(err && !error) {
error = err;
cb(err);
} else {
results[i] = result;
done();
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment