Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

前者表述的含义setTimeout和setInterval在timers阶段执行,后者表示setTimeout和setInterval在poll阶段执行,是否自相矛盾? #16

Open
wangduanduan opened this issue Aug 19, 2021 · 0 comments

Comments

@wangduanduan
Copy link

你的文章中写道下面的两个, 前者表述的含义setTimeout和setInterval在timers阶段执行,后者表示setTimeout和setInterval在poll阶段执行,是否自相矛盾?

每个阶段(phase)的作用:timers:执行 setTimeout() 和 setInterval() 中到期的 callback。

poll 阶段主要有两个功能:
当 timers 的定时器到期后,执行定时器(setTimeout 和 setInterval)的 callback。
执行 poll 队列里面的 I/O callback。

我们看nodejs官方的解释: 这个解释的含义应该是: poll阶段会取回所有的io事件, 执行相关的io回调(换句话说:是除了timers和setimmediate之外的所有事件)。 按照官方的解释,poll阶段并不会执行定时器相关的回调。

poll: retrieve new I/O events; execute I/O related callbacks (almost all with the exception of close callbacks, the ones scheduled by timers, and setImmediate()); node will block here when appropriate. https://nodejs.org/en/docs/guides/event-loop-timers-and-nexttick/

@wangduanduan wangduanduan changed the title 你的文章中写道下面的两个, 前者表述的含义setTimeout和setInterval在timers阶段执行,后者表示setTimeout和setInterval在poll阶段执行,是否自相矛盾? 前者表述的含义setTimeout和setInterval在timers阶段执行,后者表示setTimeout和setInterval在poll阶段执行,是否自相矛盾? Aug 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant