Skip to content

Instantly share code, notes, and snippets.

@ngauthier
Created July 18, 2012 14:35
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ngauthier/3136546 to your computer and use it in GitHub Desktop.
Save ngauthier/3136546 to your computer and use it in GitHub Desktop.
Daisy-Chaining setTimeout
// 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