I have two functions that do asynchronous things. When they have finished, I want to execute the rest of my code.
Of course if I do this:
myFuncA();
myFuncB();
// rest of my code
The rest is executed even if they didn't ended.
I tried this:
var a = false;
var b = false;
a = myFuncA(); // return true when it ends
b = myFuncB(); // return true when it ends
while (!a && !b) {
// just waiting the two functions to end
}
// rest of my code
I expected the loop to end when the two functions end, but it doesn't work.
So I tried almost the same but with global variables:
var a = false;
var b = false;
myFuncA(); // value a = true when it ends
myFuncB(); // value b = true true when it ends
while (!a && !b) {
// just waiting the two functions to end
}
// rest of my code
But it doesn't work either.
So my question is: what is the method for waiting for the results of async functions to continue the code execution?