async function funcTwo() {
return new Promise((r) => r());
}
async function funcOne() {
console.log("A");
(async () => {
await funcTwo();
console.log("B");
})();
console.log("C");
}
await funcOne();
console.log("Done");
According to my knowledge the output should be as follows:
A
C
B
Done
My reasoning is:
1.funcOne
runs
2.A
is printed
3.async function runs and promise is resolved immediately thus console.log("B")
is moved to the mircotask queue
4.C
is printed
5.funcOne is resolved and console.log("Done");
is moved to the mircotask queue.
6.Tasks are fetched from the queue and B
and Done
are printed in that order. (console.log("B")
is added to the queue before console.log("done")
)
However the output is:
A
C
Done
B
B
and Done
are switched
Can someone explain what I got wrong?