src/utils/Async.js
function doSequentiallyInBackground(items, fnProcessItem, maxBlockingTime, idleTime) {

        maxBlockingTime = maxBlockingTime || 15;
        idleTime = idleTime || 30;

        var sliceStartTime = (new Date()).getTime();

        return doSequentially(items, function (item, i) {
            var result = new $.Deferred();

            // process the next item
            fnProcessItem(item, i);

            // if we've exhausted our maxBlockingTime
            if ((new Date()).getTime() - sliceStartTime >= maxBlockingTime) {
                //yield
                window.setTimeout(function () {
                    sliceStartTime = (new Date()).getTime();
                    result.resolve();
                }, idleTime);
            } else {
                //continue processing
                result.resolve();
            }

            return result;
        }, false);
    }
function doSequentiallyInBackground(items, fnProcessItem, maxBlockingTime, idleTime) {

        maxBlockingTime = maxBlockingTime || 15;
        idleTime = idleTime || 30;

        var sliceStartTime = (new Date()).getTime();

        return doSequentially(items, function (item, i) {
            var result = new $.Deferred();

            // process the next item
            fnProcessItem(item, i);

            // if we've exhausted our maxBlockingTime
            if ((new Date()).getTime() - sliceStartTime >= maxBlockingTime) {
                //yield
                window.setTimeout(function () {
                    sliceStartTime = (new Date()).getTime();
                    result.resolve();
                }, idleTime);
            } else {
                //continue processing
                result.resolve();
            }

            return result;
        }, false);
    }
function doSequentiallyInBackground ( items , fnProcessItem , maxBlockingTime , idleTime ) { maxBlockingTime = maxBlockingTime || 15 ; idleTime = idleTime || 30 ; var sliceStartTime = ( new Date ( ) ) . getTime ( ) ; return doSequentially ( items , function ( item , i ) { var result = new $ . Deferred ( ) ; // process the next item fnProcessItem ( item , i ) ; // if we've exhausted our maxBlockingTime if ( ( new Date ( ) ) . getTime ( ) - sliceStartTime >= maxBlockingTime ) { //yield window . setTimeout ( function ( ) { sliceStartTime = ( new Date ( ) ) . getTime ( ) ; result . resolve ( ) ; } , idleTime ) ; } else { //continue processing result . resolve ( ) ; } return result ; } , false ) ; }
Executes a series of synchronous tasks sequentially spread over time-slices less than maxBlockingTime.
Processing yields by idleTime between time-slices.

@param {!Array.<*>} items
@param {!function(*, number)} fnProcessItem  Function that synchronously processes one item
@param {number=} maxBlockingTime
@param {number=} idleTime
@return {$.Promise}
Executes a series of synchronous tasks sequentially spread over time - slices less than maxBlockingTime . Processing yields by idleTime between time - slices .