About this question
In the below code I am making a Server Call using async/await. Once I get the results I want to process the results and then move along after the .Then statement. The problem seems to be that Promise is still Pending so it is skipping the .Then and running the console.Log first after the .Then. How can I get the code to wait?
export function onBeforePriceRules(quote, lineModels, conn) {
let myServerResults = GetData(conn);
let ProcessResults = myServerResults;
console.log(ProcessResults) // Promise {}
ProcessResults.then(function(result) {
//Do stuff with the Results.
console.log(result);
debugger;
})
console.log("New Code Block = This is firing before my .Then Statement because Promise is still Pending But I am using async and await");
debugger;
return Promise.resolve();
}
async function GetData(conn) {
// Await for the query results
return await conn.query("SELECT Id, Model__c FROM Product2")
.then(returnedRecords => { return returnedRecords } )
}