Last active
September 8, 2016 13:41
-
-
Save pietrom/8d8171668a8703f36ce9ab83d669ff64 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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