//串行有關(guān)聯(lián)的時(shí)候,上一個(gè)函數(shù)的執(zhí)行需要給下一個(gè)函數(shù)傳遞數(shù)據(jù)
async.waterfall([
//函數(shù)1
function(callback){
setTimeout(function(){
callback(null,"first...");
},2000)
},
//函數(shù)2
function(arr1,callback){
setTimeout(function(){
callback(null,arr1,"second...");
},2000)
},
//函數(shù)3
function(arr1,arr2,callback){
setTimeout(function(){
callback(null,[arr1,arr2,"three..."]);
},2000)
}
],
//回調(diào)函數(shù)
function(err,result){
console.log(result);
console.timeEnd("time");
});
/*
結(jié)果的顯示:
[ 'first...', 'second...', 'three...' ]
time: 6018.157ms
*/