-
-
Save kulbida/31d1495301b9c9a23051 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
// if we have | |
function do() { | |
// thing that takes 100ms - 2s depending on browser | |
} | |
// Instead of: | |
setInterval(do, 500) // pray it doesn't lock the browser | |
// Do this: | |
function doAndTick() { | |
do(); | |
setTimeout(doAndTick, 100); | |
} | |
doAndTick(); | |
// It will not run exactly every 500, but it guarantees 100ms of downtime for the browser |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment