The execution order of nextTick and setImmediate in node

process.nextTick(() => {
  console.log("nextTick");
});

setImmediate(() => {
  console.log("setImmediate1");
  process.nextTick(() => {
    console.log("");
  });
});

setImmediate(() => {
  console.log("setImmediate2");
});

the result of the execution of this code in the higher version of node is:

nextTick
setImmediate1
setImmediate2

node says in this book that the callback functions of process.nextTick () are saved in an array, and each round of Tick will execute all the callback functions in the array; setImmediate () results are saved in the linked list, and each round of Tick only executes one callback function, which is not consistent with the above implementation results?

Mar.30,2021
In the
check phase, two setImmediate callbacks are found to be executed, and another nextTick is generated during the first setImmediate callback, but I don't care. I haven't passed the check phase, so finish my callback first, and wait for the check phase to complete the execution of nextTick at the end.

Menu