priority between setTimeout and setImmediate

前端 未结 1 1027
盖世英雄少女心
盖世英雄少女心 2021-02-14 19:32

I read this on the node documentation :

setImmediate(callback, [arg], [...])

To schedule the \"immediate\" execution of callback after I/O

相关标签:
1条回答
  • 2021-02-14 19:51

    You should check this github issue

    The event loop cycle is timers -> I/O -> immediates, rinse and repeat. The documentation is correct but incomplete: it doesn't mention that when you haven't entered the event loop yet (as is the case in your example), then timers come first - but only on the first tick. (In master. To complicate matters, things work slightly less deterministic in v0.10.)

    0 讨论(0)
提交回复
热议问题