Created
October 4, 2011 12:04
-
-
Save hughfdjackson/1261472 to your computer and use it in GitHub Desktop.
javascript sleep function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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