Created
December 5, 2015 22:56
-
-
Save tonyonodi/e9b4e6d16996f29e3cee to your computer and use it in GitHub Desktop.
Pause function for JS
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
// 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