Skip to content

Instantly share code, notes, and snippets.

@tonyonodi
Created December 5, 2015 22:56
Show Gist options
  • Save tonyonodi/e9b4e6d16996f29e3cee to your computer and use it in GitHub Desktop.
Save tonyonodi/e9b4e6d16996f29e3cee to your computer and use it in GitHub Desktop.
Pause function for JS
// I'm not proud of this but JS has forced my hand
function pause(time) {
if (typeof time !== "number") {
throw("time should be a number in milliseconds");
}
var endTime;
endTime = (new Date()).getTime() + time;
while(1) {
var newTime = (new Date()).getTime();
if (newTime > endTime) {
return;
}
}
}
console.log("start");
// wait (roughly) 1 second
pause(1000);
console.log("finish");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment