async.waterfall

Posted Tekkaman

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了async.waterfall相关的知识,希望对你有一定的参考价值。

async.waterfall

  if any of the tasks pass an error to their own callback, the next function is not executed, and the main callback is immediately called with the error.

技术分享
async.waterfall([
    function(callback) {
        callback(null, ‘one‘, ‘two‘);
    },
    function(arg1, arg2, callback) {
        // arg1 now equals ‘one‘ and arg2 now equals ‘two‘
        callback(null, ‘three‘);
    },
    function(arg1, callback) {
        // arg1 now equals ‘three‘
        callback(null, ‘done‘);
    }
], function (err, result) {
    // result now equals ‘done‘
});
View Code
技术分享
// Or, with named functions:
async.waterfall([
    myFirstFunction,
    mySecondFunction,
    myLastFunction,
], function (err, result) {
    // result now equals ‘done‘
});
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, callback) {
    // arg1 now equals ‘three‘
    callback(null, ‘done‘);
}
View Code

 

参考:https://caolan.github.io/async/docs.html#waterfall

以上是关于async.waterfall的主要内容,如果未能解决你的问题,请参考以下文章

Node.js 中 For 循环中的 async.waterfall

nodejs 和 async.waterfall 带有 if 条件和条件函数列表。

nodejs 和 async.waterfall 带有 if 条件和条件函数列表。

async.waterfall 和 child_process.execSync 有啥区别?

async.series / async.waterfall在post方法中有效吗?

for 循环内的 async.waterfall 转义 for 循环