Reputation: 55729
Node.js exposes process.nextTick
, which ensures that the callback supplied is invoked upon return of control to the runtime. This runs the risk of "starving the event loop", by preventing evaluation of jobs on the Job Queue.
Internet Explorer exposes setImmediate
which, as far as I can tell, uses a separate Job Queue and some logic so that the items are popped off the queue once per loop iteration, precluding "event loop starvation".
requestAnimationFrame
maintains its own queue of callbacks that will be invoked one after the other, immediately before the VBLANK of the graphics subsystem.
Is it correct to say that the JavaScript runtime coordinates the running of jobs from various queues by supplying them to the event loop for execution at times determined by algorithms specific to those queues, and that in some sense what is going on is more complicated that a single event loop being served by a single Job Queue?
Upvotes: 4
Views: 322
Reputation: 5535
How the queue works and if there is more than one is implementation-specific, but it is possible to have more than one queue and special rules that state which job from which queue is going to be run first.
Upvotes: 1