const anotherAsync = async () => {
console.log('Another async called');
for (let i=0; i<=100000; i++) {
}
console.log('Another async finished');
};
const func = async () => {
console.log('async func called');
anotherAsync();
console.log('async func finished');
};
const run = async () => {
console.log('calling async func');
await func();
console.log('done');
};
run();
The result:
calling async func
async func called
Another async called
Another async finished
async func finished
done
Here, as you can see I am awaiting only on func function. anotherAsync is not awaited. So, logically I would assume async func finished and done to be printed before Another async called as anotherAsync() should be in microtask queue untill the callstack is not yet empty. But here it does not seem to be the case.
Will appreciate if someone can help me understand why Another async function is printed before async func finished
My assumption is that, anotherFunc is part of func which is why await on func does trigger an implicit await on anotherFunc or prioritizes the execution of those instructions for that function