以下代码仅返回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
库遵循常见的 Node.js 模式:error
-first 回调。
要表示任务“成功”,第一个参数应为falsy(通常为null
),第二个参数为任意数据或在论证之后。
callback(null, workloadinfo);
callback(null, pricingDetail);
function (error, result) {
if (error) {
// handle the error...
} else {
console.log(result);
}
}
另请注意 async.waterfall()
旨在将结果从一个任务传递到下一个任务,仅得出最终任务的结果
(或错误
)。
如果您想收集每个任务的结果,请尝试 async.series()
。有了它,result
将是从每个任务传递的数据的Array
。
关于javascript - async.waterfall 仅返回函数数组的 array[0] 索引处的函数结果集 - Node js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18052215/