You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* `saturated` - A callback that is called when the `queue.length()` hits the concurrency and further tasks will be queued.
1292
1293
* `empty` - A callback that is called when the last item from the `queue` is given to a `worker`.
1293
1294
* `drain` - A callback that is called when the last item from the `queue` has returned from the `worker`.
1294
-
* `idle()`, `pause()`, `resume()`, `kill()` - cargo inherits all of the same methods and event calbacks as [`queue`](#queue)
1295
+
* `idle()`, `pause()`, `resume()`, `kill()` - cargo inherits all of the same methods and event callbacks as [`queue`](#queue)
1295
1296
1296
1297
__Example__
1297
1298
@@ -1420,6 +1421,77 @@ function(err, results){
1420
1421
1421
1422
For a complicated series of `async` tasks, using the [`auto`](#auto) function makes adding new tasks much easier (and the code more readable).
1422
1423
1424
+
---------------------------------------
1425
+
<a name="autoInject" />
1426
+
### autoInject(tasks, [callback])
1427
+
1428
+
A dependency-injected version of the [`auto`](#auto) function. Dependent tasks are specified as parameters to the function, after the usual callback parameter, with the parameter names matching the names of the tasks it depends on. This can provide even more readable task graphs which can be easier to maintain.
1429
+
1430
+
If a final callback is specified, the task results are similarly injected, specified as named parameters after the initial error parameter.
1431
+
1432
+
The autoInject function is purely syntactic sugar and its semantics are otherwise equivalent to [`auto`](#auto).
1433
+
1434
+
__Arguments__
1435
+
1436
+
* `tasks` - An object, each of whose properties is a function of the form
1437
+
'func([dependencies...], callback). The object's key of a property serves as the name of the task defined by that property, i.e. can be used when specifying requirements for other tasks.
1438
+
* The `callback` parameter is a `callback(err, result)` which must be called when finished, passing an `error` (which can be `null`) and the result of the function's execution. The remaining parameters name other tasks on which the task is dependent, and the results from those tasks are the arguments of those parameters.
1439
+
* `callback(err, [results...])` - An optional callback which is called when all the tasks have been completed. It receives the `err` argument if any `tasks` pass an error to their callback. The remaining parameters are task names whose results you are interested in. This callback will only be called when all tasks have finished or an error has occurred, and so do not not specify dependencies in the same way as `tasks` do. If an error occurs, no further `tasks` will be performed, and `results` will only be valid for those tasks which managed to complete.
1440
+
1441
+
1442
+
__Example__
1443
+
1444
+
The example from [`auto`](#auto) can be rewritten as follows:
1445
+
1446
+
```js
1447
+
async.autoInject({
1448
+
get_data:function(callback){
1449
+
// async code to get some data
1450
+
callback(null, 'data', 'converted to array');
1451
+
},
1452
+
make_folder:function(callback){
1453
+
// async code to create a directory to store a file in
1454
+
// this is run at the same time as getting the data
If you are using a minifier that mangles parameter names, `autoInject` will not work with plain functions. To work around this, you can explicitly specify the names of the parameters in an array, similar to Angular.js dependency injection.
0 commit comments