Skip to content

Instantly share code, notes, and snippets.

@tit
Created Jun 21, 2015
Embed
What would you like to do?
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