关于将async.waterfall()中的参数传递给第三个函数而不是第一个函数,我有一个问题。例如,如下所示
async.waterfall([
first,
second,
async.apply(third, obj)
], function(err, result){});现在可以在名为third的函数中使用"obj“作为参数,也可以使用名为第二的回调函数传递的参数。
发布于 2016-03-29 19:07:10
是。你可以做到的。见下文。请看最后一个函数。
var async = require('async');
async.waterfall([
myFirstFunction,
mySecondFunction,
async.apply(myLastFunction, 'deen'),
], function (err, result) {
console.log(result);
});
function myFirstFunction(callback) {
callback(null, 'one', 'two');
}
function mySecondFunction(arg1, arg2, callback) {
// arg1 now equals 'one' and arg2 now equals 'two'
callback(null, 'three');
}
function myLastFunction(arg1, arg2, callback) {
// arg1 is what you have passed in the apply function
// arg2 is from second function
callback(null, 'done');
}https://stackoverflow.com/questions/36292378
复制相似问题