setimmediate

Why Node.js setImmediate executes after I/O callbacks?

馋奶兔 提交于 2019-12-11 02:35:28
问题 As new member, I'm unable to comment on topics, that's why I had to create a new topic. But in this way, I can clarify the problem, so hopefully you guys can help me. I have read quite a lot about Node.js Event Loop. And I have shaped my understanding of it based on following materials: Node.js Event Loop What the heck is the event loop anyway? Why setImmediate() execute before fs.readFile() in Nodejs Event Loop's works? (Please feel free to suggest other materials which are informative and

setImmediate vs. nextTick

喜你入骨 提交于 2019-11-26 01:26:39
问题 Node.js version 0.10 was released today and introduced setImmediate . The API changes documentation suggests using it when doing recursive nextTick calls. From what MDN says it seems very similar to process.nextTick . When should I use nextTick and when should I use setImmediate ? 回答1: Use setImmediate if you want to queue the function behind whatever I/O event callbacks that are already in the event queue. Use process.nextTick to effectively queue the function at the head of the event queue