Last active
May 30, 2018 20:42
-
-
Save langjt/a3e1305a4cd500b4bddcf4a1e3ee83eb to your computer and use it in GitHub Desktop.
sleep in js
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
function sleep(milliseconds) { | |
var start = new Date().getTime(); | |
for (var i = 0; i < 1e7; i++) { | |
if ((new Date().getTime() - start) > milliseconds){ | |
break; | |
} | |
} | |
} | |
const start = +new Date; | |
console.log('Dude!'); | |
sleep(10000); | |
const end = +new Date; | |
console.log('end-start='+(end-start)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment