JavaScript Event Loop: Queue vs Message Queue vs Event Queue

ぐ巨炮叔叔 提交于 2019-12-04 12:03:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!