There is the poll
stage of the Node js's event loop. Its aim is to blockingly wait for I/O notifications and then execute needed callbacks. A timeout time of the waiting is calculated before entering this stage. If there were operations scheduled through setImmediate
than the timeout is set at 0, if timers took place than timeout is set with a view of them and if there are no such impediments the blocking would continue "forever".
What will happen if the timeout is initially set at "infinity" and an I/O callback schedules a function with setImmediate
or setInterval
? Would the timeout be recalculated immediately or only after the I/O queue got empty (in a next loop iteration)?
So if we wait for two launched asynchronous opearations with callbacks A
and B
and after receiving an I/O notification A
is executed and it in turn schedules some C
function with setImmediate
what the function would execute first B
or C
?