Promise waterfall

This question already has an answer here:

  • How to structure nested Promises 2 answers

  • You've got a promise anti pattern happening. You can return promises from promises to avoid nesting the promises like you've done.

    promiseOne()
        .then(() => promiseTwo())
        .then(() => promiseThree())
        .then(() => promiseFour());
    

    By the way Node supports the built in Promise constructor.

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise

    const promise = new Promise((resolve, reject) => {
        // do something and then resolve
        resolve();
    })
    promise().then(() => { ... });
    
    链接地址: http://www.djcxy.com/p/9450.html

    上一篇: Javascript Promises嵌套深度就像回调

    下一篇: 诺言瀑布