diff options
author | Alexander Early <alexander.early@gmail.com> | 2015-10-25 17:16:46 -0700 |
---|---|---|
committer | Alexander Early <alexander.early@gmail.com> | 2015-10-25 17:16:46 -0700 |
commit | 4a536f12d4126bda284869d0756956370e53ee21 (patch) | |
tree | 537f1b5982b60f779f6100f3268b931cddaa569d | |
parent | fbeab9b9979ebd7d5987592e01d25328ee410f56 (diff) | |
download | async-4a536f12d4126bda284869d0756956370e53ee21.tar.gz |
move concurrency arg position in auto (#637)
-rw-r--r-- | README.md | 5 | ||||
-rw-r--r-- | lib/async.js | 7 | ||||
-rwxr-xr-x | test/test-async.js | 4 |
3 files changed, 10 insertions, 6 deletions
@@ -1256,7 +1256,7 @@ cargo.push({name: 'baz'}, function (err) { --------------------------------------- <a name="auto" /> -### auto(tasks, [callback], [concurrency]) +### auto(tasks, [concurrency], [callback]) Determines the best order for running the functions in `tasks`, based on their requirements. Each function can optionally depend on other functions being completed first, and each function is run as soon as its requirements are satisfied. @@ -1302,13 +1302,12 @@ __Arguments__ called when finished, passing an `error` (which can be `null`) and the result of the function's execution, and (2) a `results` object, containing the results of the previously executed functions. +* `concurrency` - An optional `integer` for determining the maximum number of tasks that can be run in parallel. By default, as many as possible. * `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. Results are always returned; however, if an error occurs, no further `tasks` will be performed, and the results object will only contain partial results. -* `concurrency` - An `integer` for determining the maximum number of tasks that - can be run in parallel. By default, as many as possible. __Example__ diff --git a/lib/async.js b/lib/async.js index 644dccb..beb1372 100644 --- a/lib/async.js +++ b/lib/async.js @@ -509,7 +509,12 @@ } }; - async.auto = function (tasks, callback, concurrency) { + async.auto = function (tasks, concurrency, callback) { + if (!callback) { + // concurrency is optional, shift the args. + callback = concurrency; + concurrency = null; + } callback = _once(callback || noop); var keys = _keys(tasks); var remainingTasks = keys.length; diff --git a/test/test-async.js b/test/test-async.js index 34fabaf..ac72fed 100755 --- a/test/test-async.js +++ b/test/test-async.js @@ -352,12 +352,12 @@ exports['auto concurrency'] = function (test) { task4: ['task1', 'task2', makeCallback('task4')], task5: ['task2', makeCallback('task5')], task6: ['task2', makeCallback('task6')] - }, function(err, results){ + }, concurrency, function(err, results){ Object.keys(results).forEach(function(taskName) { test.ok(results[taskName].length <= concurrency); }); test.done(); - }, concurrency); + }); }; exports['auto petrify'] = function (test) { |