understanding the node.js event queue and process.nextTick

后端 未结 2 1013
清歌不尽
清歌不尽 2020-12-16 05:16

I\'m having trouble understanding exactly how process.nextTick does its thing. I thought I understood, but I can\'t seem to replicate how I feel this should wor

2条回答
  •  长情又很酷
    2020-12-16 05:37

    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.

提交回复
热议问题