What promise are you waiting for?

async function - don't wait for the promise

What you need to understand is that async / await doesn't keep your code running in sync, instead you write it as if it is:

In short: the function with async in front of it is literally executed asynchronously, hence the keyword "async". And the await keyword causes the line it uses in this asynchronous function to wait for a promise while executing. Although the line is waiting, the entire function continues to run asynchronously unless the caller of this function is also waiting.

Explained in more detail: If you put async in front of a function, it means that it is returning a promise with the contents of that function. The function is executed asynchronously, and when the return statement is executed, the promise dissolves the return value.

That is, in your code:

The "getResult ()" function returns a promise that is resolved after the execution is completed. Therefore, the lines in the getResult () function are executed asynchronously unless you tell the function calling getResult () to wait for them as well. Inside the getResult () function you can say that it has to wait for the result. This causes the execution of getResult () to wait for the promise to be resolved. However, the caller to getResult () will not wait unless you tell the caller to wait.

So a solution would be either:

Or if you work in a different function you can just use 'wait' again