Skip to content

Instantly share code, notes, and snippets.

@alxrocha
Forked from seanmonstar/Array.batch.js
Created October 27, 2010 07:01
Show Gist options
  • Save alxrocha/648590 to your computer and use it in GitHub Desktop.
Save alxrocha/648590 to your computer and use it in GitHub Desktop.
Array.implement('batch', function(callback, loopsPerBatch, delay, bind) {
if(!loopsPerBatch) loopsPerBatch = 10;
if(!delay) delay = 50;
if(callback) {
var loops = 0,
index = 0,
that = this;
function doLoops() {
loops = 0;
for (var length = that.length; (index < length) && loops < loopsPerBatch; index++) {
loops++;
callback.call(bind, that[index], index, that);
}
if(index < length) {
doLoops.delay(delay);
}
}
doLoops();
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment