We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
setImmediate和process.nextTick都会在下一个 event loop 时执行,但是它们有如下区别:
setImmediate
process.nextTick
setImmediate(handler) 并不像 setTimeout(handler, 0) 由event loop检测系统时间是否到点然后向事件队列插入一个事件,然后调用事件的回调方法handler。而是监控UI线程的调用栈,一旦调用栈为空则将handler压栈。
setImmediate(handler)
setTimeout(handler, 0)
The text was updated successfully, but these errors were encountered:
引用:process.nextTick()属于idle观察者,setImmediate()属于check观察者.在每一轮循环检查中,idle观察者先于I/O观察者,I/O观察者先于check观察者.
Sorry, something went wrong.
补个图
请教一下这个图用什么做的啊
No branches or pull requests
setImmediate
和process.nextTick
都会在下一个 event loop 时执行,但是它们有如下区别:setImmediate
不会call stack,可以用于大规模异步递归调用。而process.nextTick
受到 maxTickDepth(默认为1000) 的限制,超过其数值会出错。setImmediate(handler)
并不像setTimeout(handler, 0)
由event loop检测系统时间是否到点然后向事件队列插入一个事件,然后调用事件的回调方法handler。而是监控UI线程的调用栈,一旦调用栈为空则将handler压栈。setImmediate
可视为“排队等候的人”,而 process.nextTick 是“插队的人”,其区别可见下图:其中“等待队列”可以是诸如A事件之前触发的 setTimeout 时间队列
The text was updated successfully, but these errors were encountered: