function loop() {
// Anything you want to run in a loop can be here
setImmediate(loop);
}
loop();
In this case, a setImmediate
callback is calling another setImmediate
whose callback is eventually to the queue (of the "Check" phase). Thus loop()
runs repeatedly
Does only one setImmediate
callback run per iteration of the event loop? i.e. does loop()
only run once per iteration of the event loop?
I often hear that setImmediate
is used to run a callback on the next "tick" or iteration of the event loop
However, the official Node documentation on the event loop (https://nodejs.org/en/docs/guides/event-loop-timers-and-nexttick/) says:
"generally, when the event loop enters a given phase, it will perform any operations specific to that phase, then execute callbacks in that phase's queue until the queue has been exhausted or the maximum number of callbacks has executed."
This makes me think that potentially multiple setImmediate
callbacks are run per iteration of the event loop. If this is the case, how can we know how many setImmediate
callbacks are executed per "tick"?
Thanks for your help!