Skip to content

Instantly share code, notes, and snippets.

@kulbida
Forked from ngauthier/settimeout.js
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kulbida/31d1495301b9c9a23051 to your computer and use it in GitHub Desktop.
Save kulbida/31d1495301b9c9a23051 to your computer and use it in GitHub Desktop.
// 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