Skip to content
Browse files

don't pass callback to last function in waterfall chain

  • Loading branch information...
1 parent 10b2ad0 commit 99ffdb9110772e4d86816af14ebef2184dfb6c2e @caolan committed May 13, 2010
Showing with 7 additions and 2 deletions.
  1. +4 −1 lib/async.js
  2. +3 −1 test/test-async.js
View
5 lib/async.js
@@ -55,7 +55,10 @@ exports.waterfall = function(arr){
i++;
if(i < arr.length){
var args = Array.prototype.slice.call(arguments);
- arr[i].apply(null, args.concat(arguments.callee));
+ if(i < arr.length-1){
+ args = args.concat(arguments.callee)
+ }
+ arr[i].apply(null, args);
}
})();
};
View
4 test/test-async.js
@@ -51,7 +51,7 @@ exports.testAuto = function(test){
};
exports.testWaterfall = function(test){
- test.expect(6);
+ test.expect(7);
var call_order = [];
async.waterfall([
function(callback){
@@ -74,6 +74,8 @@ exports.testWaterfall = function(test){
function(arg4, callback){
call_order.push('fn4');
test.same(call_order, ['fn1','fn2','fn3','fn4']);
+ // don't pass callback to last in waterfall chain
+ test.ok(callback === undefined);
test.done();
}
]);

0 comments on commit 99ffdb9

Please sign in to comment.
Something went wrong with that request. Please try again.