diff options
author | Caolan McMahon <caolan.mcmahon@gmail.com> | 2014-03-28 15:44:24 +0000 |
---|---|---|
committer | Caolan McMahon <caolan.mcmahon@gmail.com> | 2014-03-28 15:44:24 +0000 |
commit | 2c34634492d39cb6d70e3e3a581a4b3703b55be3 (patch) | |
tree | 250797b19321dacd5660fa02b9e66af96f58fd9d | |
parent | 8f93f6ac6fa5a377c87252b07482926f3933f5e3 (diff) | |
parent | 63b7d80b1b806decc65e384399710aa592d78d4a (diff) | |
download | async-2c34634492d39cb6d70e3e3a581a4b3703b55be3.tar.gz |
Merge pull request #318 from aearly/feature/dountil-params
Pass params from doUntil/doWhilst callbacks to the test function
-rwxr-xr-x | lib/async.js | 7 | ||||
-rwxr-xr-x | test/test-async.js | 57 |
2 files changed, 62 insertions, 2 deletions
diff --git a/lib/async.js b/lib/async.js index 5c7f737..04f7246 100755 --- a/lib/async.js +++ b/lib/async.js @@ -1,3 +1,4 @@ +/*jshint onevar: false, indent:4 */ /*global setImmediate: false, setTimeout: false, console: false */ (function () { @@ -641,7 +642,8 @@ if (err) { return callback(err); } - if (test()) { + var args = Array.prototype.slice.call(arguments, 1); + if (test.apply(null, args)) { async.doWhilst(iterator, test, callback); } else { @@ -669,7 +671,8 @@ if (err) { return callback(err); } - if (!test()) { + var args = Array.prototype.slice.call(arguments, 1); + if (!test.apply(null, args)) { async.doUntil(iterator, test, callback); } else { diff --git a/test/test-async.js b/test/test-async.js index 539acc8..fdcac5f 100755 --- a/test/test-async.js +++ b/test/test-async.js @@ -1834,6 +1834,34 @@ exports['doUntil'] = function (test) { ); }; +exports['doUntil callback params'] = function (test) { + var call_order = []; + var count = 0; + async.doUntil( + function (cb) { + debugger + call_order.push(['iterator', count]); + count++; + cb(null, count); + }, + function (c) { + call_order.push(['test', c]); + return (c == 5); + }, + function (err) { + test.same(call_order, [ + ['iterator', 0], ['test', 1], + ['iterator', 1], ['test', 2], + ['iterator', 2], ['test', 3], + ['iterator', 3], ['test', 4], + ['iterator', 4], ['test', 5] + ]); + test.equals(count, 5); + test.done(); + } + ); +}; + exports['whilst'] = function (test) { var call_order = []; @@ -1892,6 +1920,35 @@ exports['doWhilst'] = function (test) { ); }; +exports['doWhilst callback params'] = function (test) { + var call_order = []; + + var count = 0; + async.doWhilst( + function (cb) { + call_order.push(['iterator', count]); + count++; + cb(null, count); + }, + function (c) { + call_order.push(['test', c]); + return (c < 5); + }, + function (err) { + debugger + test.same(call_order, [ + ['iterator', 0], ['test', 1], + ['iterator', 1], ['test', 2], + ['iterator', 2], ['test', 3], + ['iterator', 3], ['test', 4], + ['iterator', 4], ['test', 5] + ]); + test.equals(count, 5); + test.done(); + } + ); +}; + exports['queue'] = function (test) { var call_order = [], delays = [160,80,240,80]; |