compose創建一個包括一組異步函數的函數集合,每個函數會消費上一次函數的返回值。把f(),g(),h()異步函數,組合成f(g(h()))的形式,通過callback得到返回值。
通過compose組合,f(g(h()))的形式,從內層到外層的執行的順序。
var async = require('async');
function a(id,cb){
console.log("@@@@@@@@@function a:"+id);
cb(null,"function a"+new Date().getTime());
}
function b(id,cb){
console.log("@@@@@@@@@function b:"+id);
cb(null,"function b"+new Date().getTime());
}
function c(id,cb){
console.log("@@@@@@@@@function c:"+id);
cb(null,"function c cb:"+new Date().getTime());
}
var fu = async.compose(a,b,c);
fu(66,function(err,result){
console.log("====="+result);
});
result---------------------------------
@@@@@@@@@function c:4
@@@@@@@@@function b:function c cb:1404995404342
@@@@@@@@@function a:function b1404995404343
=====function a1404995404344