异步等待在数组映射中以不希望的方式工作

时间:2019-07-05 15:59:05

标签: javascript node.js

我在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

0 个答案:

没有答案