Created
May 28, 2011 06:47
-
-
Save jnx/996672 to your computer and use it in GitHub Desktop.
Sleep function for Javascript
This file contains hidden or 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
/* Usage | |
* alert("Hi"); | |
* sleep(2000); // Sleep 2sec | |
* alert("Goodby"); | |
*/ | |
function sleep(milliseconds) { | |
var start = new Date().getTime(); | |
for (var i = 0; i < 1e7; i++) { | |
if ((new Date().getTime() - start) > milliseconds){ | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment