Skip to content

Commit

Permalink
Merge pull request #822 from megawac/reduce-while
Browse files Browse the repository at this point in the history
Implement *until via *while
  • Loading branch information
aearly committed Jul 1, 2015
2 parents c312a05 + f0553cf commit 4d8bac6
Showing 1 changed file with 6 additions and 24 deletions.
30 changes: 6 additions & 24 deletions lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -819,33 +819,15 @@
};

async.until = function (test, iterator, callback) {
callback = callback || noop;
if (!test()) {
iterator(function (err) {
if (err) {
return callback(err);
}
async.until(test, iterator, callback);
});
}
else {
callback(null);
}
return async.whilst(function() {
return !test.apply(this, arguments);
}, iterator, callback);
};

async.doUntil = function (iterator, test, callback) {
callback = callback || noop;
iterator(_restParam(function (err, args) {
if (err) {
return callback(err);
}
if (!test.apply(null, args)) {
async.doUntil(iterator, test, callback);
}
else {
callback(null);
}
}));
return async.doWhilst(iterator, function() {
return !test.apply(this, arguments);
}, callback);
};

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

0 comments on commit 4d8bac6

Please sign in to comment.