考虑这个代码,其中start
,continue
和finish
是承诺。
export const do = () => {
return new Promise((resolve, reject) => {
start()
.then(() => continue())
.then(() => finish())
.then(() => resolve())
.catch((reason) => reject(reason))
});
};
这是如何编写嵌套的promises?
答案 0 :(得分:1)
只需返回整个链条,无需包裹它:
export const _do = () => start()
.then(continue)
.then(finish)
;