Skip to content

Instantly share code, notes, and snippets.

@domfarolino
Created April 3, 2018 06:50
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 domfarolino/e3cbcce4d12639c014846089c4e31d9c to your computer and use it in GitHub Desktop.
Save domfarolino/e3cbcce4d12639c014846089c4e31d9c to your computer and use it in GitHub Desktop.
Synchronous timer in JavaScript
/**
* 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