Created
September 28, 2013 12:13
-
-
Save xk/6741466 to your computer and use it in GitHub Desktop.
Shows that node's timers are borken and execute out of order.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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