1

Initially I have question about the order of number in code

(function() {
    setTimeout(() => console.log(1), 0);
    Promise.resolve(true).then(() => console.log(2));
})();

And for myself I've explained it like setTimeout uses 4ms in fact instead of 0.

But code works in same manner with setImmediate

(function() {
    setImmediate(() => console.log(1), 0);
    Promise.resolve(true).then(() => console.log(2));
})();

Man who asked the question said that the reason is the fact, that in v8 Promises is not part of webapis and run inside loops.

Maybe there are any other explanations? Or links to find more details?

If I use Loupe for visualization I see the same

Loupe visualization - I'm looking for explanation

Vasiliy vvscode Vanchuk
  • 7,007
  • 2
  • 21
  • 44

0 Answers0