以下代码仅返回getpricingSummary 的结果集
async.waterfall([
function(callback){
getpricingSummary(elementsParam, function(workloadinfo) {
callback(workloadinfo);
});
},
function(callback){
getPricingforResourceIdentifiers('vm/hpcloud/nova/small,image/hpcloud/nova/ami-00000075', function(pricingDetail) {
callback(pricingDetail);
});
}],
function(result){
console.log(result);
});
]);
async
库遵循error
的常见Node.js模式-第一次回调。
为了表示任务"成功",第一个参数应为falsy(通常为null
),任何数据都应作为第二个或之后的参数。
callback(null, workloadinfo);
callback(null, pricingDetail);
function (error, result) {
if (error) {
// handle the error...
} else {
console.log(result);
}
}
还要注意,async.waterfall()
旨在将结果从一个任务传递到下一个任务,仅从最后一个任务(或error
)到达result
。
如果要收集每个任务的结果,请尝试async.series()
。有了它,result
将是每个任务传递的数据的Array
。