Skip to content

Instantly share code, notes, and snippets.

@kekscom
Created August 12, 2015 21:09
Show Gist options
  • Select an option

  • Save kekscom/800e8894dbb722760ce1 to your computer and use it in GitHub Desktop.

Select an option

Save kekscom/800e8894dbb722760ce1 to your computer and use it in GitHub Desktop.

Revisions

  1. Jan Marsch created this gist Aug 12, 2015.
    19 changes: 19 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@

    function relax(callback, startIndex, dataLength, chunkSize, delay) {
    chunkSize = chunkSize || 1000;
    delay = delay || 1;

    var endIndex = startIndex + Math.min((dataLength-startIndex), chunkSize);

    if (startIndex === endIndex) {
    return;
    }

    callback(startIndex, endIndex);

    if (startIndex < dataLength) {
    setTimeout(function() {
    relax(callback, endIndex, dataLength, chunkSize, delay);
    }, delay);
    }
    }