Skip to content

Instantly share code, notes, and snippets.

@jkevingutierrez
Last active May 3, 2018 14:42
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 jkevingutierrez/c3ed78a12469567124e44c474cd7377a to your computer and use it in GitHub Desktop.
Save jkevingutierrez/c3ed78a12469567124e44c474cd7377a to your computer and use it in GitHub Desktop.
Functions that simulate sync sleep
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
}
for (let i=1; i<10; i++) {
setTimeout(function timer(){
console.log(i);
}, i*3000 );
}
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