Trying to replicate a C# application in Angular is proving to be challenging for me, particularly when it comes to ensuring that the code runs synchronously.
Consider the following example:
private void doChecks()
{
if (isInvoiced())
return;
Console.WriteLine("Done");
}
private bool isInvoiced()
{
var invID = Server.GetInvoice(mAccID);
if (invID <= 0)
return false;
else
return someOtherFunction(invID);
}
When attempting to implement this behavior in Angular, I am uncertain how to achieve the same sequential execution without relying on async/await
methods.
async doChecks() {
const doAllChecks = await this.service.DoChecks(this.mAcc).toPromise();
if (await this.isInvoiced()) {
return;
}
Console.log("Done");
}
async isInvoiced() {
const invID = await this.service.GetInvoice(this.mAcc).toPromise();
if (invID <= 0)
return false;
else {
const data = await someOtherFunction(invID); // Now this function will also need to be async so I can await inside it for its http request to finish.
return data;
}
}
Is there a simpler way to achieve this?