gpt4 book ai didi

javascript - 如何编写嵌套的 Promise

转载 作者:太空宇宙 更新时间:2023-11-04 16:20:58 25 4
gpt4 key购买 nike

考虑一下这段代码,其中 startcontinuefinish 是 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com