Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/watson/after-all-results
Like after-all, but collects the results for you
https://github.com/watson/after-all-results
Last synced: 28 days ago
JSON representation
Like after-all, but collects the results for you
- Host: GitHub
- URL: https://github.com/watson/after-all-results
- Owner: watson
- License: mit
- Created: 2014-08-16T21:24:59.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-01-31T17:04:49.000Z (over 9 years ago)
- Last Synced: 2024-05-12T06:40:59.400Z (about 1 month ago)
- Language: JavaScript
- Size: 199 KB
- Stars: 9
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Lists
- awesome-nodejs-precise - after-all-results - all-results .svg?style=social&label=Star&maxAge=2592000?style=flat-square)]() | Bundle results of async functions calls into one callback with all the results. | (Packages / Control flow Callbacks)
- awesome-nodejs - after-all-results - Bundle results of async functions calls into one callback with all the results. (Packages / Control flow)
- awesome-nodejs-cn - after-all-results - Bundle results of async functions calls into one callback with all the results. (包 / Control flow)
README
# after-all-results
If you have multiple async function calls that you want to run in
parallel and collect all their results in an array, this is the module
for you.It's like [after-all](https://github.com/sorribas/after-all) with a
build in results aggregator.[![build status](https://secure.travis-ci.org/watson/after-all-results.png)](http://travis-ci.org/watson/after-all-results)
## Installation
```
npm install after-all-results
```## Usage
First require the module:
```javascript
var afterAll = require('after-all-results');
```Then initialize with a callback that should be called once all the async
stuff is done:```javascript
var next = afterAll(function (err, results) {
// all done!
console.log(results);
});
```The returned `next` function is essentially just a smart
callback-generator. The after-all-results module will wait and not call
the all-done function until all the generated callbacks have been
called:```javascript
someAsyncFunction(next());
anotherAsyncFunction(next());
```**Note:** It is important that all `next()` calls are done on the same
tick as the inital call to `afterAll()`!### Bonus: Inception mode
```javascript
var next = afterAll(function (err, results) {
// results will be an array of `arg1` from below
console.log('Done with everything!');
});async(next(function (err, arg1, arg2) {
console.log('Done with first call to async');
});async(next(function (err, arg1, arg2) {
console.log('Done with second call to async');
});
```## License
MIT