async.waterfall只返回函数数组(node js)的array[0]索引处的函数的结果集
async.waterfall returns only the resultset of function at array[0] index of array of functions - node js
以下代码仅返回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
。
相关文章:
- 如何迭代Array.prototype函数
- 检测未绑定的本机函数,如“Array.push”
- ASP MVC 将 Array 对象发送到 JavaScript 函数
- Array.from 在 Array#map 中不能用作直接回调函数
- 将参数传递给 Array.forEach 回调函数
- Javascript Array 的求和函数问题
- "可变变量可从闭包“”访问;在传递给Array.prototype.every的函数中
- 在JavaScript中调用array()作为构造函数时,返回的是什么类型的数组
- Array.insert函数错误,因为Object函数Array(){〔本机代码〕}没有方法'插入'
- jQuery的返回值是Array,但构造函数是Object.如何
- JavaScript 的 Array 调用和函数在 Prototype 中失败
- 为什么 Array.Length = 1 当空数组通过 ajax 传递给函数时
- 若将Array对象添加到Array原型中,则不遍历该对象的函数
- 如何将codeigniter DB array传递给JavaScript函数
- 获取 Array.forEach 函数的返回值
- array.forEach之后的回调函数
- Array.map 和 Javascript 中的提升函数
- 返回不同类型的JavaScript函数(Array vs NodeList)
- 试着理解这个函数:Array.prototype.reverse = function(){
- 我可以创建一个javascript数组函数array.method()吗