await AsyncCall1;
console.log("one");
await AsyncCall2;
console.log("two");
Is equal to:
AsyncCall1.then(function(){
console.log("one");
AsyncCall2.then(function(){
console.log("two");
});
});
How does this get executed?
One actually cant tell. That depends when the promises are resolved. However one will always be logged before two.
Does AsyncCall1 finish before AsyncCall2 starts or are they started in parallel?
Its impossible to say because you dont start the promising function, you just await the results. If you would do:
await asyncFunc1();
await asyncFunc2();
Then asyncFunc2 will only be called (/started) after the first function resolved. However if you do:
const promise1 = asyncFunc(), promise2 = asyncFunc();
await promise1;
await promise2;
Then both promises will be started at nearly the same time, then the code will continue the execution after awaiting both. Note that you should add proper error handling here, e.g. catch
errors before awaiting (read on here):
const promise1 = asyncFunc().catch(e => null);
const promise2 = asyncFunc().catch(e => null);
What happens in the interim before they both have results?
The js engine executes something else. When both are finished it jumps back to the position the result was awaited.