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'
}
添加回答
舉報