Created
July 21, 2015 22:04
-
-
Save soarez/be48304a644db4611b91 to your computer and use it in GitHub Desktop.
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
console.log('experiment') | |
var intervalTime = 1000; | |
setInterval(runSomething, intervalTime); | |
var lastTime = Date.now();; | |
function runSomething() { | |
var now = Date.now(); | |
var elapsed = now - lastTime; | |
lastTime = now; | |
var lag = elapsed - intervalTime; | |
console.log('Running something. Lag:', lag); | |
} | |
var count = 2000; | |
var limit = 50; | |
var scheduled, done; | |
proceed(); | |
function proceed() { | |
scheduled = 0; | |
done = 0; | |
while (count --> 0 && ++scheduled <= limit) | |
setTimeout(somethingElse(count), 500); | |
} | |
function somethingElse(count) { | |
return function() { | |
if (count % 100 === 0) | |
console.log(2000 - count); | |
var start = Date.now(); | |
while (Date.now() - start < 4); | |
done++; | |
if (done === limit) | |
proceed(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment