[英]Using asyncawait module with function
我正在使用asyncawait模塊(因為我的節點版本在服務器上不夠高,無法使用真正的async / await)。 我有以下使用await函數的函數:
function getNextParticipant(req, res) {
let nextThreeUsers = await(getNextThreeUsersInQueue())
// other things done here
}
在將此功能作為Express路由器端點的一部分使用之前,我將其包裝在async(...)
如下所示:
router.get('/getNextParticipant', async((req, res) => {
let nextThreeUsers = await(getNextThreeUsersInQueue())
// other things done here
}))
但我想在多個端點上使用它。 所以我試圖這樣稱呼它:
router.get('/getNextParticipant', (req, res) => {
return async (getNextParticipant(req, res))
})
這似乎不起作用...正確的方法是什么?
我通過將getNextParticipant更改為如下所示來解決了它,然后它起作用了:
var getNextParticipant = async((req, res) => {
// ...
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.