G
G
gmiroslav2017-01-13 23:11:31
Node.js
gmiroslav, 2017-01-13 23:11:31

Node.js setImmediate, setTimeout, how do they work?

function timeout0() {
console.log('timeout 0');
}
function immediate() {
console.log('immediate');
}
setTimeout(timeout0, 0);
setImmediate(immediate);
If you run this code 10 times, you can see that the order of the functions is different, sometimes timeout 0 fires first, and sometimes immediate. Why is that?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dark Hole, 2017-01-13
@abyrkov

Reading the doc :
Those. these are optimization lags, most likely

A
Aves, 2017-01-14
@Aves

https://nodejs.org/en/docs/guides/event-loop-timer...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question