I found myself needing this type of function a few times:
- execute several async operations in parallel
- call
done
whenever the first one finished, and ignore any subsequent results
It's easily implemented as follows, but does it belong in async
? Happy to submit a PR with unit tests.
async.first = function(ops, done) {
var i = 0;
var response = false;
for (i = 0; i < ops.length; ++i) {
ops[i](function(err, data) {
if (!response) {
response = true;
done(err, data);
}
});
}
};