我有以下代码
function someHelper(someList) {
return someList.map((item) => {
return (next) => someService.firstCall(paramForFirst, (err, result) => {
if(err) next(err);
else someService.secondCall(paramForSecond, result, next);
})
});
}
module.exports = {
doSomething(param, callback) {
async.parallel(someHelper(someList), callback);
}
};
如何将someHelper
函数的第二次返回转换为使用async.waterfall
?
答案 0 :(得分:0)
这是我的解决方案。从并行传递next
(回调),然后调用瀑布数组列表中的方法,最后调用next
。通过定义waterfall
将调用带有结果或错误的回调。
function someHelper(someList) {
return someList.map((item) => {
return (next) => {
async.waterfall([
async.apply(someService.firstCall, paramForFirst),
async.apply(someService.secondCall, paramForSecond)
], next);
}
});
}