On the difference between process.nextTick and setImmediate.

  node.js, question

When looking at the content of nodejs timer, I saw such a code
clipboard.png
After a run, the output is as follows:

clipboard.png
As if it wasn’t quite what you expected? ? After checking, it seems that’ strong insertion’ should be output between’ setimmediate delay execution 1′ and’ setimmediate delay execution 2′.

My understanding:
First, process.nextTick has a higher priority than setImmediate.
Secondly, the existing timer method is always executed according to priority, and then the timer method in asynchronous callback is executed according to priority.
Finally, the deeper the asynchronous callback hides, the lower the priority level.

Test code:

process.nextTick(function(){
 console.log('1');
 });
 process.nextTick(function(){
 console.log('2');
 });
 
 setImmediate(function(){
 console.log('3');
 setImmediate(function() {
 console.log('4');
 process.nextTick(function(){
 console.log('5');
 process.nextTick(function(){
 console.log('6');
 });
 });
 });
 process.nextTick(function(){
 console.log('7');
 });
 });
 process.nextTick(function(){
 console.log('8');
 });
 setImmediate(function(){
 console.log('9');
 process.nextTick(function(){
 console.log('10');
 });
 });
 console.log('0');

Verification output:

zero
 one
 2
 8
 3
 9
 7
 10
 4
 5
 6