chpark
chpark
Jul 21, 2017 · 1 min read

Thanks for clarifying that. I want to clarify one more thing. In the following example,

setTimeout(callback1, timeout);

setImmediate(callback2);

I think that “generally or theoretically”, the execution order of callback1 for setTimeout with the arbitrary timeout (even with the non-zero timeout) and callback2 for setImmediate is always non-deterministic. When we set a long timeout for setTimeout, callback2 would be executed first in almost all cases practically but it has a non-zero possibility for callback1 to be executed first if the thread processing the event-loop for Node.js is very slow so scheduling callback1 for setTimeout by kernel happens first before the event loop moves to the Timer phase. Am I correct? Could you let me know if I am missing something here?

    chpark

    Written by

    chpark