I know that there is a message queue and that JavaScript is single threaded. And also an event loop that receives messages from the queue and does some work.
When you create a promise, and this promise is stored in the message queue when or how the loop knows when it is resolved (or rejected). Is the question constantly asked whether the status is βpendingβ or is the promise of a message queue itself if resolved or rejected?
Update:
After some research, I think I was wrong. This is not a promise itself, but an XHR request that actually blocks and runs in its thread so as not to block the main thread of execution. Thus, only the main thread of execution is single-threaded, and the XHR thread will place callbacks in the main thread when the XHR request receives the result (or does not work).
So, the corresponding article , the promise itself is stored on the stack and will call the callback function in the queue when it is allowed?
source
share