Skip to content

Instantly share code, notes, and snippets.

@hughfdjackson
Created October 4, 2011 12:04
Show Gist options
  • Save hughfdjackson/1261472 to your computer and use it in GitHub Desktop.
Save hughfdjackson/1261472 to your computer and use it in GitHub Desktop.
javascript sleep function
// WARNINGS:: This function is *relatively* untested (i.e. there is no formal testing as of yet). Use at your own risk.
// It is normally MUCH better to use setTimeout or requestAnimationFrame than to block in a single-threaded environment, be KIND to your users
// This function is best suited to testing the behaviour of an application when intensive processing occurs
function sleep(ms){
var initial = +new Date()
while(+new Date() < initial + ms){}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment