Nikolay Podolnyy
Nikolay Podolnyy

Reputation: 1091

What is the I/O in explanation process.nextTick and setImmediate?

I read explanation about them and process.nextTick fires before Input/Output operations and setImmediate - after I/O operations, so. I understand that process.nextTick fires before all async actions and setImmediate fires after it but before setTimeout's and before setInterval's. Can someone explain and provide example - what mean I/O operations in this explanations?

Upvotes: 2

Views: 118

Answers (1)

Himanshu sharma
Himanshu sharma

Reputation: 7899

Let me describe to you what this are.

Suppose this is queue . which have three function in event loop to execute.

a , b , c

So queue is FIFO so first come first server , THat means a will execute then b, then c. So what this two function do is this. when you use

process.nextTick , when you run this the new process is added to the event loop and that added immediately behind the current process is executing.

that means.

a , new_process , b , c

in this case the new_process will execute after the current process a exit from the event loop. then b,c will execute.

and other hand

setImmediate , when you run this the new process add at the end of queue . Like this

a , b, c , new_process

So now when all a,b,c are finished then the new_process is execute .

Upvotes: 1

Related Questions