summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Early <alexander.early@gmail.com>2013-05-21 18:51:57 -0700
committerAlexander Early <alexander.early@gmail.com>2013-05-21 18:51:57 -0700
commit63b7d80b1b806decc65e384399710aa592d78d4a (patch)
tree7684ea40a6239a505336b49090d92de579235807
parentebec545152d6623f81922405006d1957c1d3de97 (diff)
downloadasync-63b7d80b1b806decc65e384399710aa592d78d4a.tar.gz
pass params from doUntil/doWhile callbacks to the test function
-rwxr-xr-xlib/async.js7
-rwxr-xr-xtest/test-async.js57
2 files changed, 62 insertions, 2 deletions
diff --git a/lib/async.js b/lib/async.js
index 46f4f50..dbf8533 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 () {
@@ -627,7 +628,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 {
@@ -655,7 +657,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 ff401e7..0cb7bb0 100755
--- a/test/test-async.js
+++ b/test/test-async.js
@@ -1711,6 +1711,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 = [];
@@ -1769,6 +1797,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];