【发布时间】:2020-08-01 20:05:39
【问题描述】:
我有一个案例,如果之前的操作成功,我会发送电子邮件。
Promise.all([doSomeAction(), sendMailIfSuccess()]) // both of them are promises
.then(() => success)
.catch(() => err);
但是,如果 doSomeAction() 承诺在 sendMailIfSuccess 解析之前失败,则无论如何都会发送邮件。但它不应该。
问题:如何仅在doSomeAction 解决后才调用sendMailIfSuccess 承诺? sendMailIfSuccess 承诺应该等待 doSomeAction 承诺。
【问题讨论】:
标签: javascript asynchronous ecmascript-6 promise async-await