I got a problem with resolution of setTimeout. When I set it to 50 ms, it varies from 51 to even 80 ms. When I use sleep module, I am able to get resolution like 50 μs, so what is the setTimeout function problem to get at least 1 ms? Is there any way to fix/avoid that? The problem with sleep is that it delays everything even when callback function should be shoot, it waits... Is there an alternative solution to shoot some events in delay of exactly 50 ms?
For example with sleep module:
var start = new Date().getTime();
sleep.usleep(50);
console.log(new Date().getTime() - start);`
Result is: 0. And microtime says it is 51 to 57 μs. So what the hell?
See Question&Answers more detail:os