Preferrance order for execution- Nexttick > SetImmediate > Settimeout
@yashbansal2526 Жыл бұрын
Whatever you. have taught about priority is wrong, please correct it, anyone watching this please don't get confuse and do a simple google search
@shubhamsoni6013 Жыл бұрын
Checked the same on Apple Mac, 1.4 GHz Quad-Core Intel Core i5, 16 GB 2133 MHz LPDDR3, Intel Iris Plus Graphics 645 1536 MB index.ts setTimeout(function(){ console.log("Settimeout") }) setImmediate(function(){ console.log("Setimmediate") }) command: npx ts-node index.ts result: Setimmediate Settimeout & sometime reverse. So as per my opinion, you would be never knowing which callback function will be called first until you know in which phase your event loop is. Thread is open for comments. Floor is yours!!
@dharmeast3 жыл бұрын
But we add some time say 1000 in setTimeOut , then setImmediate will be called first.
@sachinyadav-of4wh2 жыл бұрын
what we are not using SetTimeout and setImmediate in the I/O phase it is not necessary that settimeout will call first. It all depends on system's current operations. anything setimmediate/SetTimeout can be called first.
@sarojjangid84662 жыл бұрын
Nice sir ♥️
@rishu6052 жыл бұрын
Whatever you have explained related to setImmediate and setTimeout priorities is completely wrong. setImmediate has a higher priority than setTimeout when it is running in an I/O cycle. Since you are running this code outside of an I/O cycle, the order of executon is NOT guaranteed and the system can execute any callback first.