Last active
August 30, 2016 09:19
-
-
Save alsotang/9c85686ffb886e63f4c72ccca24c55a8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 forceInterval(fn, time) { | |
var lastRunTime = new Date(); | |
return setInterval(function () { | |
var currentTime = new Date() | |
if ((new Date - lastRunTime) < time) { | |
fn(); | |
} else { | |
var count = ~~((new Date - lastRunTime) / time) | |
for (var i = 0; i < count; i++) { | |
fn() | |
} | |
} | |
lastRunTime = currentTime; | |
}, time) | |
} |
This file contains hidden or 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
var count = 0; | |
setInterval(function () { | |
count++; | |
console.log(count) | |
}, 100) | |
var startTime = +new Date() | |
while ((new Date - startTime) > 2000) { | |
} | |
setTimeout(function () { | |
console.log('after 1200ms:', count) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment