In NodeJS: is it possible for two callbacks to be executed exactly at the same time?
node.js
Solution
No, every callback will be executed in its own "execution frame". In other languages "parallel execution" and potential conflicts as locks caused by that are possible if operations occur in different threads.
Problem
Let's say I have this code: ``` function fn(n) { return function() { for(var k = 0; k <= 1000; ++k) { fs.writeSync(process.stdout.fd, n+"\n"); } } } setTimeout(fn(1), 100); setTimeout(fn(2), 100); ``` Is it possible that `1` and `2` will be printed to `stdout` interchangeably (e.g. `12121212121...`)? I've tested this and they did NOT apper interchangeably, i.e. `1111111...222222222...`, but few tests are far from proof and I'm worried that something like `111111211111...2222222...` could happen. In other words: when I register some callbacks and event handlers in Node can two callbacks be executed exactly at the same time? (I know this could be possible with launching two processes, but then we would have two `stdout` and the above code would be splitted into separate files, etc.) Another question: Forgetting the Node and speaking generally: in any language on single process is it possible for two functions to be executed at exactly the same time (i.e. in the same manner as above)?