auto-async
Version:
auto run async dependencies
49 lines (39 loc) • 1.24 kB
Markdown
async dependencies on the fly. In addition to what `async.auto` and `autorun` does, auto-async does resolve all the possible async tasks by not stopping on the first error.
```javascript
var autoAsync = require('auto-async');
autoAsync(asyncDef, callback, continueOnError);
```
```javascript
var autoAsync = require('auto-async');
var asyncDef = {
a: function a(cb, results) {
console.log('a');
cb(null, {key: 'a'});
},
b: ['a', function b(cb, results) {
console.log('b');
cb(null, {key: 'b'});
}],
c: ['b', function c(cb, results) {
console.log('c');
cb(null, {key: 'c'});
}]
};
autoAsync(asyncDef, function onResponse(err, results, state) {
// err - first error encountered
// results - all resolved nodes
// state - status of each node err/response
});
```
continueOnError flag controls if the async resolution should stop on the first error or continue to resolve as many async tasks as possible.
```
autoAsync(asyncDef, function onResponse(err, results, state) {
// err - in case graph fails
// results - all possible resolved nodes
// state - status of each node err/response
}, true);
```
Auto magically resolves