Last active
          November 25, 2021 11:06 
        
      - 
      
 - 
        
Save neilk/5380684 to your computer and use it in GitHub Desktop.  
Revisions
- 
        
neilk renamed this gist
Apr 14, 2013 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. - 
        
neilk revised this gist
Apr 14, 2013 . 1 changed file with 4 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,9 @@ /** * Allow other processes to execute while iterating over * an array. Useful for large arrays, or long-running processing * * @param {Function} fn iterator fed each element of the array. * @param {Function} next executed when done */ Array.prototype.nonBlockingForEach = function(fn, next) { var arr = this;  - 
        
neilk created this gist
Apr 13, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ /** * Allow other processes to execute while iterating over the elements * of an array. Only useful if you're iterating over very large arrays, * or if each iteration needs to do some long-running, non-async processing. * * @param {Function} fn iterator that gets fed each element of the array. * @param {Function} next callback executed when all elements have been iterated over. */ Array.prototype.nonBlockingForEach = function(fn, next) { var arr = this; var i = 0; var len = arr.length; function iter() { if (i < len) { fn(arr[i]); i++; process.nextTick(iter); } else { next(); } } iter(); };