understanding the node.js event queue and process.nextTick

不打扰是莪最后的温柔 提交于 2019-11-29 02:19:14

process.nextTick put the callback on the next tick that is going to be executed, not at the end of the tick queue.

Node.js doc (http://nodejs.org/api/process.html#process_process_nexttick_callback) say: "It typically runs before any other I/O events fire, but there are some exceptions."

setTimeout(callback, 0) will probably work more like you describe.

You should certainly read the link fgascon provided, and perhaps

https://github.com/joyent/node/issues/3335 for more background.

Use process.nextTick for when you want to call some code before any IO, but after the calling context has returned (usually because you want to register listeners on an event emitter and need to return the created emitter before you can register anything).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!