Skip to content

Commit

Permalink
Implement doWhilst via whilst
Browse files Browse the repository at this point in the history
  • Loading branch information
megawac committed Jul 1, 2015
1 parent c312a05 commit b4059e8
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -791,31 +791,26 @@
async.whilst = function (test, iterator, callback) {
callback = callback || noop;
if (test()) {
iterator(function (err) {
var next = _restParam(function(err, args) {
if (err) {
return callback(err);
callback(err);
} else if (test.apply(this, args)) {
iterator(next);
} else {
callback(null);
}
async.whilst(test, iterator, callback);
});
}
else {
iterator(next);
} else {
callback(null);
}
};

async.doWhilst = function (iterator, test, callback) {
callback = callback || noop;
iterator(_restParam(function (err, args) {
if (err) {
return callback(err);
}
if (test.apply(null, args)) {
async.doWhilst(iterator, test, callback);
}
else {
callback(null);
}
}));
var calls = 0;
return async.whilst(function() {
return ++calls <= 1 || test.apply(this, arguments);
}, iterator, callback);
};

async.until = function (test, iterator, callback) {
Expand Down

0 comments on commit b4059e8

Please sign in to comment.