flw.js
function each(items, numParralel, fn, done) {
    if (done === undefined) {
      done = fn; fn = numParralel;
      numParralel = 3;
    }

    if (numParralel <= 0) numParralel = 1;

    let doing = 0;
    let numProcessing = 0;
    let numDone = 0;
    const numTotal = items.length;
    const results = [];
    return nextItem();

    function nextItem() {
      // We done-check first in case of emtpty array
      if (numDone >= numTotal) return done(null, results);

      // Batch (or call next item)
      while (doing < numTotal && numProcessing < numParralel) {
        callFn(fn, items[doing++], onDone);
        numProcessing++;
      }
      return;

      // All done
      function onDone(err, result) {
        if (err) return done(err);

        results.push(result);
        numProcessing--;
        numDone++;
        return nextItem();
      }
    }
  }
function each(items, numParralel, fn, done) {
    if (done === undefined) {
      done = fn; fn = numParralel;
      numParralel = 3;
    }

    if (numParralel <= 0) numParralel = 1;

    let doing = 0;
    let numProcessing = 0;
    let numDone = 0;
    const numTotal = items.length;
    const results = [];
    return nextItem();

    function nextItem() {
      // We done-check first in case of emtpty array
      if (numDone >= numTotal) return done(null, results);

      // Batch (or call next item)
      while (doing < numTotal && numProcessing < numParralel) {
        callFn(fn, items[doing++], onDone);
        numProcessing++;
      }
      return;

      // All done
      function onDone(err, result) {
        if (err) return done(err);

        results.push(result);
        numProcessing--;
        numDone++;
        return nextItem();
      }
    }
  }
function each ( items , numParralel , fn , done ) { if ( done === undefined ) { done = fn ; fn = numParralel ; numParralel = 3 ; } if ( numParralel <= 0 ) numParralel = 1 ; let doing = 0 ; let numProcessing = 0 ; let numDone = 0 ; const numTotal = items . length ; const results = [ ] ; return nextItem ( ) ; function nextItem ( ) { // We done-check first in case of emtpty array if ( numDone >= numTotal ) return done ( null , results ) ; // Batch (or call next item) while ( doing < numTotal && numProcessing < numParralel ) { callFn ( fn , items [ doing ++ ] , onDone ) ; numProcessing ++ ; } return ; // All done function onDone ( err , result ) { if ( err ) return done ( err ) ; results . push ( result ) ; numProcessing -- ; numDone ++ ; return nextItem ( ) ; } } }
Calls fn with every item in the array
@param {any[]} items Array items to process
@param {Number} [numParallel] Limit parallelisation (default: 3)
@param {function} fn function call for each item
@param {function} done callback
Calls fn with every item in the array