Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for breaking a waterfall chain #85

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,12 +439,15 @@
else {
var args = Array.prototype.slice.call(arguments, 1);
var next = iterator.next();
var iteratorCallback;
if (next) {
args.push(wrapIterator(next));
iteratorCallback = wrapIterator(next);
}
else {
args.push(callback);
iteratorCallback = callback;
}
iteratorCallback.final = callback;
args.push(iteratorCallback);
async.nextTick(function () {
iterator.apply(null, args);
});
Expand Down
25 changes: 25 additions & 0 deletions test/test-async.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,31 @@ exports['waterfall multiple callback calls'] = function(test){
async.waterfall(arr);
};

exports['waterfall final'] = function(test){
var call_order = [];
var arr = [
function(callback){
call_order.push(1);
callback();
},
function(callback){
call_order.push(2);
callback.final(null, 'a result');
},
function(callback){
test.ok(false, 'next callback should not be reached');
call_order.push(3);
callback();
}
];
async.waterfall(arr, function(err, result){
call_order.push(4);
test.same(call_order, [1, 2, 4], 'call order');
test.equal(err, null, 'no error should be passed');
test.equal(result, 'a result');
test.done();
});
};

exports['parallel'] = function(test){
var call_order = [];
Expand Down