Skip to content

Instantly share code, notes, and snippets.

@kekscom
Created August 12, 2015 21:09
Show Gist options
  • Save kekscom/800e8894dbb722760ce1 to your computer and use it in GitHub Desktop.
Save kekscom/800e8894dbb722760ce1 to your computer and use it in GitHub Desktop.
relax()
function relax(callback, startIndex, dataLength, chunkSize, delay) {
chunkSize = chunkSize || 1000;
delay = delay || 1;
var endIndex = startIndex + Math.min((dataLength-startIndex), chunkSize);
if (startIndex === endIndex) {
return;
}
callback(startIndex, endIndex);
if (startIndex < dataLength) {
setTimeout(function() {
relax(callback, endIndex, dataLength, chunkSize, delay);
}, delay);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment