[Pkg-javascript-commits] [node-async] 332/480: pass params from doUntil/doWhile callbacks to the test function
Jonas Smedegaard
js at moszumanska.debian.org
Fri May 2 08:58:39 UTC 2014
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository node-async.
commit 63b7d80b1b806decc65e384399710aa592d78d4a
Author: Alexander Early <alexander.early at gmail.com>
Date: Tue May 21 18:51:57 2013 -0700
pass params from doUntil/doWhile callbacks to the test function
---
lib/async.js | 7 +++++--
test/test-async.js | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
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];
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-async.git
More information about the Pkg-javascript-commits
mailing list