function pool(promiseFactories, limit) {
  return new PouchPromise$1(function (resolve, reject) {
    var running = 0;
    var current = 0;
    var done = 0;
    var len = promiseFactories.length;
    var err;

    function runNext() {
      running++;
      promiseFactories[current++]().then(onSuccess, onError);
    }

    function doNext() {
      if (++done === len) {
        /* istanbul ignore if */
        if (err) {
          reject(err);
        } else {
          resolve();
        }
      } else {
        runNextBatch();
      }
    }

    function onSuccess() {
      running--;
      doNext();
    }

    /* istanbul ignore next */
    function onError(thisErr) {
      running--;
      err = err || thisErr;
      doNext();
    }

    function runNextBatch() {
      while (running < limit && current < len) {
        runNext();
      }
    }

    runNextBatch();
  });
}
// but much smaller in code size. limits the number of concurrent promises that are executed
but much smaller in code size. limits the number of concurrent promises that are executed
but much smaller in code size . limits the number of concurrent promises that are executed
function pool(promiseFactories, limit) {
  return new PouchPromise$1(function (resolve, reject) {
    var running = 0;
    var current = 0;
    var done = 0;
    var len = promiseFactories.length;
    var err;
    function runNext() {
      running++;
      promiseFactories[current++]().then(onSuccess, onError);
    }
    function doNext() {
      if (++done === len) {
        if (err) {
          reject(err);
        } else {
          resolve();
        }
      } else {
        runNextBatch();
      }
    }
    function onSuccess() {
      running--;
      doNext();
    }
    function onError(thisErr) {
      running--;
      err = err || thisErr;
      doNext();
    }
    function runNextBatch() {
      while (running < limit && current < len) {
        runNext();
      }
    }
    runNextBatch();
  });
}
function pool ( promiseFactories , limit ) { return new PouchPromise$1 ( function ( resolve , reject ) { var running = 0 ; var current = 0 ; var done = 0 ; var len = promiseFactories . length ; var err ; function runNext ( ) { running ++ ; promiseFactories [ current ++ ] ( ) . then ( onSuccess , onError ) ; } function doNext ( ) { if ( ++ done === len ) { if ( err ) { reject ( err ) ; } else { resolve ( ) ; } } else { runNextBatch ( ) ; } } function onSuccess ( ) { running -- ; doNext ( ) ; } function onError ( thisErr ) { running -- ; err = err || thisErr ; doNext ( ) ; } function runNextBatch ( ) { while ( running < limit && current < len ) { runNext ( ) ; } } runNextBatch ( ) ; } ) ; }
but much smaller in code size.
but much smaller in code size .
/* istanbul ignore if */ /* istanbul ignore next */