Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.