Skip to content

Instantly share code, notes, and snippets.

@iizukanao
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iizukanao/cf12a8c402310c6418de to your computer and use it in GitHub Desktop.
Save iizukanao/cf12a8c402310c6418de to your computer and use it in GitHub Desktop.
setTimeout issues on Node v0.10.30
var counter = 0;
function queueNext() {
if (++counter === 100) {
return;
}
console.log(counter);
setTimeout(function() {
queueNext();
}, 12.34);
}
queueNext();
var startTime = process.hrtime();
var sleepMs = 100; // milliseconds
setTimeout(function() {
var diff = process.hrtime(startTime);
var elapsedMs = diff[0] * 1000 + diff[1] / 1000000;
console.log('expected=' + sleepMs + 'ms, got=' + elapsedMs + 'ms');
}, sleepMs);
@iizukanao
Copy link
Author

$ node -v
v0.10.30
$ node too_early.js
expected=100ms, got=56.605771ms
$ node hang.js
1
2
3
4
5
(hangs forever)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment