Reputation: 1125
I know about the event loop and how it operated. Recently i read to understand well about promises and learnt that one of the differences between ECS6
and the lower specifications it that. The javascript engine now has infulence on how tasks are scheduled on the event loop queue.
Now there is this new notion of a job queue
that is said to live at the end of an iteration of the event loop. Can someone please clearly explain to me What the job queue
is ,how it operates and how it helps in scheduling tasks on the event loop queue. I seem not to get a clear expalanation from anywhere.
Upvotes: 1
Views: 756
Reputation: 19301
The "job queue" that "appears at the end of the event loop queue iteration" is commonly called the "micro task queue".
Jobs added to the micro queue are simply executed in succession, after the current call-out from the event loop finishes, without the event loop manager making any decision on what to run next, until the micro queue is empty.
Promise reaction jobs, caused to be run by promise settlement, are placed in the micro queue. Hence they run at top priority immediately after any active call-out from the event queue has finished.
The ES6 specification simply states that Promise jobs go into a "PromiseJob" queue without specifying implementation details for any particular JavaScript application such as a browser, and without mentioning the words "micro task".
A related question, What is the difference between “event loop queue” and “job queue”?, contains additional definitions and links for the formal definition of what a "job queue" is.
Upvotes: 1