DEV Community

Discussion on: setTimeout vs setImmediate vs process.nextTick

Collapse
anduser96 profile image
Andrei Gatej

Thanks for pointing out the difference between them!

One thing confuses me:

Finally, we have setTimeout. /* ... */, but it does run after I/0 events and after setImmediate.

So if it runs after setImmediate, why is timeout printed before immediate?

Collapse
logicmason profile image
Mark Author • Edited

Clearly my model of how this works is wrong! I did some research in writing this, but the timeout is running first here.

Time to do some more investigation and revise this. Thanks!

Edit: setImmediate callbacks go into the "close" queue! I've updated the post.