according to my understanding of the event loop mechanism of nodejs, if the poll queue is not empty in the poll phase, the queue will be traversed and the callback will be executed. When the poll queue is listed as empty, the callback of the next phase of setImmediate () will be executed.
the problem comes from the following code:
`setTimeout (() = > {
console.log (timer callback executed after "0ms")
}, 0)
readFile (".. / package.json", "utf-8", data = > {
console.log (" callback for completing the file"s first read operation")
})
setImmediate (() = > {
console.log ("immediate callback now")
})
process.nextTick (() = > {
console.log ("callback of process.nextTick")
}) `
output result:
callback of process.nextTick
timer callback executed after 0 milliseconds
immediate immediate callback
callback to complete the first read operation of the file
Why do I execute the callback of setImmediate instead of readFile first?