nodeJS design pattern to break out of a async.waterfall or promise.then.then

This question already has an answer here:

  • How to properly break out of a promise chain? 3 answers

  • 通过承诺,您可以将“后续承诺”附加到您需要的执行分支:

    a("some data")
    .then(function(data) {
        if(data) { 
            return "foo";//other promises won't be executed here
        } else {
           return b("some data").then(c).then(d)
        }
    })
    .catch(function(err) {
        //log error
    })
    .finally(function() {
         // do something
    })
    
    链接地址: http://www.djcxy.com/p/55488.html

    上一篇: 回调不是一个函数

    下一篇: nodeJS设计模式打破异步流水或promise.then