Skip to content

Instantly share code, notes, and snippets.

@xk
Created September 28, 2013 12:13
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 xk/6741466 to your computer and use it in GitHub Desktop.
Save xk/6741466 to your computer and use it in GitHub Desktop.
Shows that node's timers are borken and execute out of order.
(function run () {
//2013.09.27 jorge@jorgechamorro.com
//Shows that node's timers are borken and often execute out of order
console.log('\nBEGIN');
var MAX= 666;
var last= 0;
var items= 0;
var errores= 0;
for (var t=0 ; items<MAX ; t+=rnd(2)) setTimeout(getitem(items++), t);
function getitem (item) {
return function itemTimeout () {
if (last>item) errores++, console.log('ERR '+last+' before '+item);
last= item;
if (!--items) console.log('END '+errores+' errores'), run();
};
}
function rnd (n) { return Math.floor(Math.random()*n) }
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment