MCPcopy
hub / github.com/Kong/insomnia / queue

Function queue

packages/insomnia/bin/yarn-standalone.js:25004–25039  ·  view source on GitHub ↗
(arr, promiseProducer, concurrency = Infinity)

Source from the content-addressed store, hash-verified

25002}
25003
25004function queue(arr, promiseProducer, concurrency = Infinity) {
25005 concurrency = Math.min(concurrency, arr.length);
25006
25007 // clone
25008 arr = arr.slice();
25009
25010 const results = [];
25011 let total = arr.length;
25012 if (!total) {
25013 return Promise.resolve(results);
25014 }
25015
25016 return new Promise((resolve, reject) => {
25017 for (let i = 0; i < concurrency; i++) {
25018 next();
25019 }
25020
25021 function next() {
25022 const item = arr.shift();
25023 const promise = promiseProducer(item);
25024
25025 promise.then(function (result) {
25026 results.push(result);
25027
25028 total--;
25029 if (total === 0) {
25030 resolve(results);
25031 } else {
25032 if (arr.length) {
25033 next();
25034 }
25035 }
25036 }, reject);
25037 }
25038 });
25039}
25040
25041/***/ }),
25042/* 48 */

Callers

nothing calls this directly

Calls 2

nextFunction · 0.70
resolveMethod · 0.45

Tested by

no test coverage detected