Take the following code taken from nodejs event loop documentation :
// timeout_vs_immediate.js
setTimeout(() => {
console.log('timeout');
}, 0);
setImmediate(() => {
console.log('immediate');
});
According to the documentation:
For example, if we run the following script, which is not included in the I / O cycle (i.e., the Main module), the order in which two timers are executed is non-deterministic, since it is related to the performance of the process.
Why is the above statement true? This is because the nodejs runtime actually uses more than one thread to select the callbacks to be executed.
: , setTimeout setImmediate , , , , .
? - , ?