Skip to content

Instantly share code, notes, and snippets.

@jnx
Created May 28, 2011 06:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jnx/996672 to your computer and use it in GitHub Desktop.
Save jnx/996672 to your computer and use it in GitHub Desktop.
Sleep function for Javascript
/* 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