I am using async module with waterfall method.
async.waterfall([
function(callback) {
...
callback(err);
},
function(result, callback) {
console.log("This function should not be executed");
}
],
function(err) {
if (err) {
next(err);
return;
}
}
);
But the second function always execute. How to prevent it?
Try adding a 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;
}
}
);
来源:https://stackoverflow.com/questions/32559822/how-to-stop-executing-waterfall-on-error-in-async-of-node-js