MCPcopy Index your code
hub / github.com/apache/pouchdb / pool

Function pool

lib/index.js:6644–6690  ·  view source on GitHub ↗
(promiseFactories, limit)

Source from the content-addressed store, hash-verified

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