gather
v0.1.0
Published
Defer function execution until all its arguments are ready
Downloads
7
Maintainers
Readme
gather
Control flow utility that runs a callback after all the dependencies are (asynchronously) met. Useful when a function depends on some resources that are obtained asynchronously and independently.
Example
var done = gather(function (a, b) {
console.log(a + b);
});
async(function () {
async(function () {
done('foo', undefined);
});
});
async(function () {
done(undefined, 'bar');
});
// Prints "foobar".
API
feed = gather(done)
Returns a function that can feed results to done
.
Pass arguments as they become ready, interleaving with undefined
for not-yet-resolved ones. The order and total count matter.
Once all the arguments are supplied, done
is finally called.
Install
npm install gather
License
MIT