如何编写嵌套的 Promise

How to write nested Promises

考虑此代码,其中 startcontinuefinish 是承诺。

export const do = () => {
    return new Promise((resolve, reject) => {
        start()
            .then(() => continue())
            .then(() => finish())
            .then(() => resolve())
            .catch((reason) => reject(reason))
    });
};

这是嵌套promise的写法吗?

只是 return 整个链,不需要包装它:

export const _do = () => start()
            .then(continue)
            .then(finish)
;