File tree Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Original file line number Diff line number Diff 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 ;
You can’t perform that action at this time.
0 commit comments