MCPcopy
hub / github.com/apache/pouchdb / pool

Function pool

lib/index.es.js:6639–6685  ·  view source on GitHub ↗
(promiseFactories, limit)

Source from the content-addressed store, hash-verified

6637
6638
6639function pool(promiseFactories, limit) {
6640 return new Promise(function (resolve, reject) {
6641 var running = 0;
6642 var current = 0;
6643 var done = 0;
6644 var len = promiseFactories.length;
6645 var err;
6646
6647 function runNext() {
6648 running++;
6649 promiseFactories[current++]().then(onSuccess, onError);
6650 }
6651
6652 function doNext() {
6653 if (++done === len) {
6654 /* istanbul ignore if */
6655 if (err) {
6656 reject(err);
6657 } else {
6658 resolve();
6659 }
6660 } else {
6661 runNextBatch();
6662 }
6663 }
6664
6665 function onSuccess() {
6666 running--;
6667 doNext();
6668 }
6669
6670 /* istanbul ignore next */
6671 function onError(thisErr) {
6672 running--;
6673 err = err || thisErr;
6674 doNext();
6675 }
6676
6677 function runNextBatch() {
6678 while (running < limit && current < len) {
6679 runNext();
6680 }
6681 }
6682
6683 runNextBatch();
6684 });
6685}
6686
6687const CHANGES_BATCH_SIZE = 25;
6688const MAX_SIMULTANEOUS_REVS = 50;

Callers 1

fetchAttachmentsFunction · 0.70

Calls 1

runNextBatchFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…