Skip to content

Instantly share code, notes, and snippets.

@ray-peters
Last active August 29, 2015 14:13
Show Gist options
  • Save ray-peters/1890c61cb83f77fd47e0 to your computer and use it in GitHub Desktop.
Save ray-peters/1890c61cb83f77fd47e0 to your computer and use it in GitHub Desktop.
// This design pattern allows you to wait without hogging up resources like
// setInterval, nor giving you an errand like clearInterval() after it's done
function doStuff(){
if ( !something.isReady ) {
setTimeout( doStuff, 50 );
return;
}
// Actually do the stuff you need to wait for
}
setTimeout( doStuff, 1000 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment