G
G
gmiroslav2016-11-22 23:41:43
JavaScript
gmiroslav, 2016-11-22 23:41:43

Node.js setTimeout, setImmediate how do they work?

When this code is called, the functions are called in a different order, please explain why?!
function a() {console.log(1);}
function b() {console.log(2);}
setTimeout(a, 0);
setImmediate(b, 0);
-------------------------------------
In this code, always strictly a, then b. Why not in the first case?
function a() {console.log(1);}
function b() {console.log(2);}
setTimeout(a, 0);
setTimeout(b, 0);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton, 2016-11-23
@pekc83

The delay in setTimeout can be from 1 to 2147483647 ms. All other values ​​are referenced to 1 ms !

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question