In my implementation, I have a basic function that invokes a method of a library. However, the issue arises when there is an if statement during execution.
The problem I am facing is that my function is being terminated before it exits the if statement. Is there a way to pause or make my function wait until the if statement is resolved?
Below is the code snippet:
public getHistory(): any {
console.log('ENTER FUNC');
this.channel.history((err: ErrorEvent, resultPage: any) => {
if (err) {
console.log(err.message);
} else {
this.messages = resultPage.items;
console.log('EXIT IF');
}
});
console.log('EXIT FUNCTION');
return this.messages;
}
Here is the output: https://i.sstatic.net/QhQoT.png
I attempted to create an async function and used await on the library's method call hoping that the function would pause until the method returns. However, the function still concluded before completing the if statement.