我在Node项目中的aync / await有问题。
我有一个需要处理的数组。我有下一个:
await Promise.all(myarray.map(async element => {
let responseEmail = await sendEmail(htmlTemplate, element)
let status
if (responseEmail.statusCode == 200) {
status = "SUCCEEDED"
const otherOperationResult = await otherOperation(element)
} else {
status = "FAILED"
}
console.log(status)
}))
const sendEmail = async (template, element) => {
console.log("sending email")
//some operations to send email
}
执行此操作时,将显示以下输出:
sending email
sending email
SUCEEDED
SUCCEDED
但是我想要的是:
sending email
SUCCEDED
sending email
SUCCEDED