node.js - async/await של nodejs לא מחכה
יש לי בלוק קוד שבו יש שני הוראות await. בפעם הראשונה שהשרת רץ, אני מאמין שהוא עובר ישר על ה-await SQL.connect. אחרי שיש כמה קריאות (המאפשרות זמן לחיבור) דרך זה, ההליך עובד בסדר.
זה עבור NodeJS, חבילת MSSQL.
למה ה-await הראשון שלי לא מחכה?
async execStoredProc(spDescriptor: StoredProcedureDescriptor) {
if (!this.pool) {
if (this.isFirst) {
this.isFirst = false ;
} else {
SQL.close();
}
this.pool = await SQL.connect(this.config);
}
try {
const request = new SQL.Request(this.pool) ;
spDescriptor.parms.forEach(function(sqlParm: SqlParm){
request.input(sqlParm.name, sqlParm.sqlType, sqlParm.value) ;
})
const qryresult = await request.execute(spDescriptor.storedProcedureName)
let result = {} ;
if (spDescriptor.multipleResultSets) {
result = qryresult.recordsets ;
} else {
result = qryresult.recordset ;
}
return result ;
} catch (err) {
console.log("SQL Error===>", err);
return [] ;
}
}