Skip to content

Commit 191aa99

Browse files
committed
Merge pull request cocos2d#2256 from SmallAiTT/cc_async_waterfall
Make cc.async.waterfall similar to async.waterfall of async.js.
2 parents acfbdc9 + 51d27cb commit 191aa99

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

CCBoot.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,19 +313,21 @@ cc.async = /** @lends cc.async# */{
313313
*/
314314
waterfall : function(tasks, cb, target){
315315
var args = [];
316+
var lastResults = [null];//the array to store the last results
316317
var asyncPool = new cc.AsyncPool(tasks, 1,
317318
function (func, index, cb1) {
318319
args.push(function (err) {
319320
args = Array.prototype.slice.call(arguments, 1);
321+
if(tasks.length - 1 == index) lastResults = lastResults.concat(args);//while the last task
320322
cb1.apply(null, arguments);
321323
});
322324
func.apply(target, args);
323-
}, function (err, results) {
325+
}, function (err) {
324326
if (!cb)
325327
return;
326328
if (err)
327329
return cb.call(target, err);
328-
cb.call(target, null, results[results.length - 1]);
330+
cb.apply(target, lastResults);
329331
});
330332
asyncPool.flow();
331333
return asyncPool;

0 commit comments

Comments
 (0)