1 year ago

#387705

test-img

user14216042

How does the browser know when a promise has resolved?

I've been learning about the event loop that browsers use and how it processes macrotasks and microtasks when they are added to their respective queues.

My question is how does the event loop know that a promise has resolved so that it can then run the microtask of the then/catch/finally code?

For example say the promise is an HTTP request. The http request is sent within some function and code execution can continue synchronously. Some time later the promise resolves and the associated then code runs.

Is the HTTP request done on some other browser thread, which when it gets the result it then adds to the microtask queue that the then code can now be executed?

javascript

google-chrome

event-handling

0 Answers

Your Answer

Accepted video resources