The reason it doesn't wait for the await is because your asynchronous function is called synchronously (without await) getQualifiedUsers()
, so it runs it, but doesn't wait for it to finish.(它不等待等待的原因是因为您的异步函数被同步调用(没有等待) getQualifiedUsers()
,因此它运行它,但不等待它完成。)
Since it seems like you are working with a promise you can change this:(由于似乎您正在兑现承诺,因此可以更改此设置:)
return t.any(Query).then(function(Response){
const getQualifiedUsers = async() => {
try{
if("meets criteria"){
try{
await insertInTable()
}catch(error){
console.log(error);
}
}
}catch(error){
console.log(error);
}
}
getQualifiedUsers();
}
into this:(到这个:)
return t.any(Query).then(async function(Response) {
try {
if ("meets criteria") {
try {
await insertInTable()
} catch(error) {
console.log(error);
}
}
} catch(error) {
console.log(error);
}
}
and it should work correctly.(它应该可以正常工作。)
EDIT: Oops I missed something in your insertInTable()
, basically the same thing so change that to the following:(编辑:糟糕,我错过了您的insertInTable()
中的insertInTable()
,基本上是同一件事,因此将其更改为以下内容:)
async function insertInTable(){
try {
await db.any(secondQuery).then(async function(numberSaved) {
try {
await sendSMS();
} catch(error){
console.log(error);
}
}
} catch(error) {
console.log(error);
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…