1 回答
TA贡献2003条经验 获得超2个赞
Promise.all一旦任何包含的承诺被拒绝,返回的承诺将被拒绝。考虑到这一点,您可以抛出哨兵值而不是返回它,只需在await.
async queryTable(query, params) {
try {
returnData = []
for await (const returnItem of api.executeQuery(query, params)){
returnData.push(returnItem)
}
if (returnData.length > 0) {
return true;
}
throw false;
}
catch (err) {
throw new Error(`${JSON.stringify(err)}`);
}
}
async validateTables() {
try {
const allDataExists = await Promise.all([
this.queryTable(query, params),
this.queryTable(query2, params2),
this.queryTable(query3, params3),
// and so on for several more
])
} catch(e) {
if(e instanceof Error) throw e
return 'Invalid'
}
return 'OK'
}
添加回答
举报