Skip to content

Commit 4a536f1

Browse files
committed
move concurrency arg position in auto (#637)
1 parent fbeab9b commit 4a536f1

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,7 @@ cargo.push({name: 'baz'}, function (err) {
12561256
---------------------------------------
12571257
12581258
<a name="auto" />
1259-
### auto(tasks, [callback], [concurrency])
1259+
### auto(tasks, [concurrency], [callback])
12601260
12611261
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.
12621262
@@ -1302,13 +1302,12 @@ __Arguments__
13021302
called when finished, passing an `error` (which can be `null`) and the result of
13031303
the function's execution, and (2) a `results` object, containing the results of
13041304
the previously executed functions.
1305+
* `concurrency` - An optional `integer` for determining the maximum number of tasks that can be run in parallel. By default, as many as possible.
13051306
* `callback(err, results)` - An optional callback which is called when all the
13061307
tasks have been completed. It receives the `err` argument if any `tasks`
13071308
pass an error to their callback. Results are always returned; however, if
13081309
an error occurs, no further `tasks` will be performed, and the results
13091310
object will only contain partial results.
1310-
* `concurrency` - An `integer` for determining the maximum number of tasks that
1311-
can be run in parallel. By default, as many as possible.
13121311
13131312
13141313
__Example__

lib/async.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,12 @@
509509
}
510510
};
511511

512-
async.auto = function (tasks, callback, concurrency) {
512+
async.auto = function (tasks, concurrency, callback) {
513+
if (!callback) {
514+
// concurrency is optional, shift the args.
515+
callback = concurrency;
516+
concurrency = null;
517+
}
513518
callback = _once(callback || noop);
514519
var keys = _keys(tasks);
515520
var remainingTasks = keys.length;

test/test-async.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -352,12 +352,12 @@ exports['auto concurrency'] = function (test) {
352352
task4: ['task1', 'task2', makeCallback('task4')],
353353
task5: ['task2', makeCallback('task5')],
354354
task6: ['task2', makeCallback('task6')]
355-
}, function(err, results){
355+
}, concurrency, function(err, results){
356356
Object.keys(results).forEach(function(taskName) {
357357
test.ok(results[taskName].length <= concurrency);
358358
});
359359
test.done();
360-
}, concurrency);
360+
});
361361
};
362362

363363
exports['auto petrify'] = function (test) {

0 commit comments

Comments
 (0)