Last active
May 3, 2018 14:42
-
-
Save jkevingutierrez/c3ed78a12469567124e44c474cd7377a to your computer and use it in GitHub Desktop.
Functions that simulate sync sleep
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; | |
} | |
} | |
} |
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
for (let i=1; i<10; i++) { | |
setTimeout(function timer(){ | |
console.log(i); | |
}, i*3000 ); | |
} |
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
var i = 0, howManyTimes = 10; | |
function f() { | |
alert( "hi" ); | |
i++; | |
if( i < howManyTimes ){ | |
setTimeout( f, 3000 ); | |
} | |
} | |
f(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment