diff options
author | ben fleis <benfleis@uber.com> | 2015-11-25 14:09:24 +0100 |
---|---|---|
committer | ben fleis <benfleis@uber.com> | 2015-11-25 16:12:43 +0100 |
commit | 8acc85db458904d48ba90c767009202de265ca2a (patch) | |
tree | f78179081c7376fbb0ea4c21b69720b5a0f37bfa | |
parent | b0797ca40b102012b582d17e1825ae81731b15da (diff) | |
download | async-8acc85db458904d48ba90c767009202de265ca2a.tar.gz |
pass last result to while/until callback
incorporate @thanodnl suggestions to pass all args
also tidy up the test changes
-rw-r--r-- | lib/async.js | 2 | ||||
-rwxr-xr-x | test/test-async.js | 38 |
2 files changed, 23 insertions, 17 deletions
diff --git a/lib/async.js b/lib/async.js index 5c17819..08af693 100644 --- a/lib/async.js +++ b/lib/async.js @@ -781,7 +781,7 @@ } else if (test.apply(this, args)) { iterator(next); } else { - callback(null); + callback.apply(null, [null].concat(args)); } }); iterator(next); diff --git a/test/test-async.js b/test/test-async.js index 5777744..6cce049 100755 --- a/test/test-async.js +++ b/test/test-async.js @@ -2812,7 +2812,7 @@ exports['concatSeries'] = function(test){ }; exports['until'] = function (test) { - test.expect(3); + test.expect(4); var call_order = []; var count = 0; @@ -2824,10 +2824,11 @@ exports['until'] = function (test) { function (cb) { call_order.push(['iterator', count]); count++; - cb(); + cb(null, count); }, - function (err) { + function (err, result) { test.ok(err === null, err + " passed instead of 'null'"); + test.equals(result, 5, 'last result passed through'); test.same(call_order, [ ['test', 0], ['iterator', 0], ['test', 1], @@ -2843,7 +2844,7 @@ exports['until'] = function (test) { }; exports['doUntil'] = function (test) { - test.expect(3); + test.expect(4); var call_order = []; var count = 0; @@ -2851,14 +2852,15 @@ exports['doUntil'] = function (test) { function (cb) { call_order.push(['iterator', count]); count++; - cb(); + cb(null, count); }, function () { call_order.push(['test', count]); return (count == 5); }, - function (err) { + function (err, result) { test.ok(err === null, err + " passed instead of 'null'"); + test.equals(result, 5, 'last result passed through'); test.same(call_order, [ ['iterator', 0], ['test', 1], ['iterator', 1], ['test', 2], @@ -2873,7 +2875,7 @@ exports['doUntil'] = function (test) { }; exports['doUntil callback params'] = function (test) { - test.expect(2); + test.expect(3); var call_order = []; var count = 0; @@ -2887,8 +2889,9 @@ exports['doUntil callback params'] = function (test) { call_order.push(['test', c]); return (c == 5); }, - function (err) { + function (err, result) { if (err) throw err; + test.equals(result, 5, 'last result passed through'); test.same(call_order, [ ['iterator', 0], ['test', 1], ['iterator', 1], ['test', 2], @@ -2903,7 +2906,7 @@ exports['doUntil callback params'] = function (test) { }; exports['whilst'] = function (test) { - test.expect(3); + test.expect(4); var call_order = []; @@ -2916,10 +2919,11 @@ exports['whilst'] = function (test) { function (cb) { call_order.push(['iterator', count]); count++; - cb(); + cb(null, count); }, - function (err) { + function (err, result) { test.ok(err === null, err + " passed instead of 'null'"); + test.equals(result, 5, 'last result passed through'); test.same(call_order, [ ['test', 0], ['iterator', 0], ['test', 1], @@ -2935,7 +2939,7 @@ exports['whilst'] = function (test) { }; exports['doWhilst'] = function (test) { - test.expect(3); + test.expect(4); var call_order = []; var count = 0; @@ -2943,14 +2947,15 @@ exports['doWhilst'] = function (test) { function (cb) { call_order.push(['iterator', count]); count++; - cb(); + cb(null, count); }, function () { call_order.push(['test', count]); return (count < 5); }, - function (err) { + function (err, result) { test.ok(err === null, err + " passed instead of 'null'"); + test.equals(result, 5, 'last result passed through'); test.same(call_order, [ ['iterator', 0], ['test', 1], ['iterator', 1], ['test', 2], @@ -2965,7 +2970,7 @@ exports['doWhilst'] = function (test) { }; exports['doWhilst callback params'] = function (test) { - test.expect(2); + test.expect(3); var call_order = []; var count = 0; async.doWhilst( @@ -2978,8 +2983,9 @@ exports['doWhilst callback params'] = function (test) { call_order.push(['test', c]); return (c < 5); }, - function (err) { + function (err, result) { if (err) throw err; + test.equals(result, 5, 'last result passed through'); test.same(call_order, [ ['iterator', 0], ['test', 1], ['iterator', 1], ['test', 2], |