【发布时间】:2018-07-31 17:38:02
【问题描述】:
我正在使用带有打字稿的续集。我知道代码是异步的,并且
在这里,我使用的是promise,并且代码有效..
我想知道什么时候必须使用 await 关键字?
const promises = []
let tabIdDoc = requestedListIdDoc.toString().split(",")
for (let thisIdDoc of tabIdDoc) {
promises.push(sequelize.models['Document'].findById(thisIdDoc))
}
q.all(promises).then((resultReq) => {
const lstDocs = []
for (let MyDoc of resultReq) {
if (MyDoc.matriculeDoc != "") {
lstDocs.push(sequelize.models['FolderDocContent'].findOrCreate({
where: {
}
}))
}
}
q.all(lstDocs).then(() => {
return response.status(201)
})
}
这里需要 await 关键字吗?
【问题讨论】:
-
await只能在async函数中使用。但是无论你可以用await做什么,你都可以不用它(使用then回调)。注意:return response.status(201)在您的代码中毫无用处,除非您在q.all(lstDocs)之前放置return。
标签: javascript asynchronous promise async-await sequelize.js