Skip to content

Instantly share code, notes, and snippets.

@learning
Created June 15, 2012 03:29
Show Gist options
  • Save learning/2934513 to your computer and use it in GitHub Desktop.
Save learning/2934513 to your computer and use it in GitHub Desktop.
timedProcessArray
function timedProcessArray(items, process, callback){
var todo = items.concat(); // Array clone
setTimeout(function(){
var start = +new Date();
do{
process(todo.shift());
}while(todo.length > 0 && (+new Date() - start < 50));
if(todo.length > 0){
setTimeout(arguments.callee, 25);
}else{
callback(items);
}
}, 25);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment