Return to Snippet

Revision: 16687
at August 12, 2009 12:19 by iTony


Initial Code
//Copyright 2009 Nicholas C. Zakas. All rights reserved.
//MIT Licensed
function timedChunk(items, process, context, callback){
    var todo = items.concat();   //create a clone of the original

    setTimeout(function(){

        var start = +new Date();

        do {
             process.call(context, todo.shift());
        } while (todo.length > 0 && (+new Date() - start < 50));

        if (todo.length > 0){
            setTimeout(arguments.callee, 25);
        } else {
            callback(items);
        }
    }, 25);
}

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

Initial Description
This method is better suited for processing large arrays in the smallest amount of time without affecting the user experience.

Initial Title
Performance in Array Processing

Initial Tags
javascript

Initial Language
JavaScript