如何在node.js的异步中停止执行错误的瀑布?

Ser*_*giy 2 waterfall node.js async.js

我正在使用瀑布方法的异步模块.

async.waterfall([
        function(callback) {
            ...
            callback(err);
        },
        function(result, callback) {
            console.log("This function should not be executed");
        }
    ],
    function(err) {
        if (err) {
            next(err);
            return;
        }
    }
);
Run Code Online (Sandbox Code Playgroud)

但第二个功能总是执行.怎么预防呢?

Ale*_*lex 6

尝试添加一个 return

async.waterfall([
        function(callback) {
            ...
            return callback(err); //note return here
        },
        function(result, callback) {
            console.log("This function should not be executed");
        }
    ],
    function(err) {
        if (err) {
            next(err);
            return;
        }
    }
);
Run Code Online (Sandbox Code Playgroud)