// 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