The output is
timer1
timer2
timer1 nextTick
timer1 resolve
- All synchronous code is run (setting the timers).
- The event loop waits (poll) for the timers to fire, then their callbacks are all called.
- Then anything in the nextTick queue is run
- Then any resolved promises run their
then
handlers - If anything is in the nextTick or promises queue at this point (because other handlers added it) jump two steps up.
- The event loop waits (poll) for the timers to fire, then their callbacks are all called...
Hey @benjamingr
why is the output for me (Node v15.12.0) different:
how did the behavior of Node/V8 change since?