DEV Community

Discussion on: Node.js Under The Hood #3 - Deep Dive Into the Event Loop

Collapse
 
barigora profile image
Igor Barchuk

log output of last example is something more complicate:
script start
promise 1
promise 2
setInterval
setTimeout 1
promise 3
promise 4
setInterval
setInterval
setTimeout 2
promise 5
promise 6

Collapse
 
_staticvoid profile image
Lucas Santos

Thanks for the reply! I'll re-evaluate the example and see if something changed!

Collapse
 
barigora profile image
Igor Barchuk

Hi, Lucas!
The output above is from Chrome browser, Ubuntu.
Here is from Node.js v10.17.0 Ubuntu:
script start
promise 1
promise 2
setInterval
setTimeout 1
promise 3
promise 4
setInterval
setTimeout 2
promise 5
promise 6

It seems environment affects how is queuing of macro tasks is.

Thread Thread
 
_staticvoid profile image
Lucas Santos

Yes, the environment might change the order of how some of the tasks are processed. Node uses libuv whereas Chrome does not.

Thread Thread
 
saru998 profile image
Saransh khobragade • Edited

Hi lucas, your explanation was great and crisp and output is also right according to your explanation setInterval wont get called. Before that settimeout 2 's micro task promises will get printed and then set interval macro task should proceed as next tick but because interval got cleared it wont.

Thread Thread
 
_staticvoid profile image
Lucas Santos

Sorry, I did not understand your question, could you please rephrase it?

Collapse
 
saru998 profile image
Saransh khobragade • Edited

Hi lucas, your explanation was great and crisp and output is also right according to your explanation setInterval wont get called. Before that settimeout 2 's micro task promises will get printed and then set interval macro task should proceed as next tick but because interval got cleared it wont.