In my understanding the REPL suppose to execute given script the same way as running it from file. What I noticed is that in the REPL mode callbacks of setImmediate are executed after tasks of setTimeout, however it is other way around when running script from file.
const test = () => {
setTimeout(() => console.log('timeout'));
setImmediate(() => console.log('immediate'));
};
test();
Reproduce-able every time.
The expected behaviour is that the event loop in the REPL mode runs callbacks of setTimeout and setImmediate in the same order as running from file.
Can you provide answers to any of the questions in the issue template? It will help us figure out if there is a bug and if so how to go about fixing it.
@devsnek Sorry, I submitted empty issue by mistake. Details provided alread.
@fredZgred The relative order of setTimeout() and setImmediate() callbacks is not guaranteed in any way, because the two callback queues are checked at different points in time on the event loop.
For example, if you replace test() with setTimeout(test), you鈥檒l get a different ordering of the two functions.
Looks like event loop made a joke on me 馃槃I tested it many times in many combinations and it gave me always the same result. Thanks for explanation and sorry bothering you.
Closing as answered then. :-)
Most helpful comment
Can you provide answers to any of the questions in the issue template? It will help us figure out if there is a bug and if so how to go about fixing it.