Created
April 3, 2018 06:50
-
-
Save domfarolino/e3cbcce4d12639c014846089c4e31d9c to your computer and use it in GitHub Desktop.
Synchronous timer in JavaScript
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
/** | |
* I often find myself needing a synchronous timer | |
* in JavaScript to test various browser things so here | |
* is a canonical timer that can be used so I don't have to | |
* keep trying to remember "What was that static function I | |
* was using on the Date class again?" | |
*/ | |
end = Date.now() + 3000; | |
while (Date.now() < end) {} | |
console.log("3 seconds later :)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment