考虑一下这段代码,其中 start
、continue
和 finish
是 promise 。
export const do = () => {
return new Promise((resolve, reject) => {
start()
.then(() => continue())
.then(() => finish())
.then(() => resolve())
.catch((reason) => reject(reason))
});
};
这是如何编写嵌套 Promise 的吗?
最佳答案
只需返回整个链,无需包装它:
export const _do = () => start()
.then(continue)
.then(finish)
;
关于javascript - 如何编写嵌套的 Promise,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40651626/