anonn – 15-18 Oct 10
Hi, I have trouble understanding how promises work in terms of the event loop.
Why is the output b,c,a
Could someone explain in terms of the event loop? e.g the image attached
What actually happens when the javascript engine reaches
Promise.resolve()
? What actually happens when the .then(b)
is reached?
I have been unable to find resources that go through step by step how interacting with Promises/Web APIs work in terms of the event loop and would be very happy if someone could point me some resources7 Replies
That is actually where I got the example, but I am still confused.
So step 1,
b
gets put into the microtask queue. How does it get there? What does Promise.resolve()
do in terms of the event loop? What does .then()
do in terms of the event loop? Who puts b
into the microtask queue? Is it the Web API?There is about sections. U can read about it.
I am confused by
So the javascript engine sees
Promise.resolve()
and returns a fulfilled promise. We go to the next line, .then(() => console.log('hi'));
. What is the step by step process that happens now?
e.g does the javascript engine see that the attached promise is resolved then throw the arrow function to the microtask queue?It's just fn (reaction on resolved promise) that microtask.
I think in about section pretty good description.
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
This thread hasn’t had any activity in 12 hours, so it’s now locked.
Threads are closed automatically after 12 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1029050226176184320