问题
Reading through a lot of JavaScript Event Loop tutorials, I see different terms to identify the queue stores messages ready to be fetched by the Event Loop when the Call Stack is empty:
- Queue
- Message Queue
- Event Queue
I can't find the canonical term to identify this.
Even MDN seems to be confused on the Event Loop page as it calls it Queue first, then says Message Queue but in the tags I see Event Queue.
Is this part of the Loop being defined somewhere in details, or it's simply an implementation detail with no "fixed" name?
回答1:
Good question, I'm also a advocate of using proper terminology.
Queue, message queue, and event queue are referring to the same construct (event loop queue). This construct has the callbacks which are fired in the event loop.
Interestingly there are two different queues the job queue and the event loop queue. The job queue is specifically designed for promises. The job queue has a higher priority than the event loop queue, so if there are both callbacks available in both queues the ones in the job queue will be put on the stack first.
Hopefully this answers your question.
来源:https://stackoverflow.com/questions/49729247/javascript-event-loop-queue-vs-message-queue-vs-event-queue