Skip to content

Instantly share code, notes, and snippets.

@tit
Created June 21, 2015 15:32
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 tit/0aab26c3b6ed49a1f6b8 to your computer and use it in GitHub Desktop.
Save tit/0aab26c3b6ed49a1f6b8 to your computer and use it in GitHub Desktop.
Sleep in JS
Number.prototype.times = function (cb) { for (var i = 0; i < +this; i++) {cb(i)} }
function sleep(ms) {var date = Date.now(); while (Date.now() - date < 1000*ms) {} }
/* example use/*
10..times(function(i){sleep(1); console.log(i);})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment