Posted By

karmacode on 05/21/11


Tagged


Versions (?)

improved timed chunk javascript function


 / Published in: JavaScript
 

URL: http://www.nczonline.net/blog/2009/08/11/timed-array-processing-in-javascript/

  1. //Copyright 2009 Nicholas C. Zakas. All rights reserved.
  2. //MIT Licensed
  3. function timedChunk(items, process, context, callback){
  4. var todo = items.concat(); //create a clone of the original
  5.  
  6. setTimeout(function(){
  7.  
  8. var start = +new Date();
  9.  
  10. do {
  11. process.call(context, todo.shift());
  12. } while (todo.length > 0 && (+new Date() - start < 50));
  13.  
  14. if (todo.length > 0){
  15. setTimeout(arguments.callee, 25);
  16. } else {
  17. callback(items);
  18. }
  19. }, 25);
  20. }

Report this snippet  

You need to login to post a comment.