异步瀑布传递参数

Async waterfall passing in arguments

我有一个关于将 async.waterfall() 中的参数传递给第三个函数而不是第一个函数的问题。例如如下

async.waterfall([
   first,
   second,
   async.apply(third, obj)
], function(err, result){});

现在可以在名为 third 的函数中使用 "obj" 作为参数,并且还可以使用从名为 [=] 的函数的回调中向下传递的参数15=]秒

是的。你可以这样做。见下文。查看最后一个函数。

    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');
    }