Skip to content

Instantly share code, notes, and snippets.

@gonghao
Created March 15, 2013 06:03
Show Gist options
  • Save gonghao/5167787 to your computer and use it in GitHub Desktop.
Save gonghao/5167787 to your computer and use it in GitHub Desktop.
var THRESHOLD = 150, DELAY = 15;
function initBigArrayAsync(max, cb) {
var r = [], i = 0;
function init(startTime) {
while (i < max) {
if (new Date - startTime < THRESHOLD) {
r[i++] = i;
} else {
setTimeout(function() {
init(new Date);
}, DELAY);
return;
}
}
cb(r);
}
init(new Date);
}
@kerryChen95
Copy link

setTimeout(function() {
  init(new Date);
}, DELAY);

could be

setTimeout(init, DELAY, new Date);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment