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AK,CAAE,GAAI,EAAI,MAAO,IAET,IAAlB,EAAO,QAAmC,IAAnB,EAAQ,OAC/B,OAAO,EAAQ,EAAS,KAAK,SAAS,KAAK,GAAS,EAAK,QAEjE,CAEA,KAAO,EAAO,OAAS,GAAK,EAAQ,OAAS,GAAO,CAChD,MAAM,GAAE,EAAE,KAAE,GAAS,EAAO,QACtB,EAAS,EAAG,EAAM,GACxB,IAAI,EAGA,EADA,aAAkB,QACR,EAGA,QAAQ,QAAQ,GAE9B,EAAQ,KAAK,CACT,KACA,QAAS,EAAQ,MAAM,GAAU,EAAK,EAAI,MAElD,CACJ,GACJ,CAUM,EACV,KACJ,CAzEA,OAAO,eAAe,QAAS,aAAc,CAAE,OAAO,IA0EtD,QAAQ,QAAU","file":"/npm/@ratwizard/for-each-queue@1.2.0/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@ratwizard/for-each-queue@1.2.0/dist/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n    return new (P || (P = Promise))(function (resolve, reject) {\n        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n        function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n        step((generator = generator.apply(thisArg, _arguments || [])).next());\n    });\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nfunction byIDAsc(a, b) {\n    if (a.id < b.id) {\n        return -1;\n    }\n    else if (a.id > b.id) {\n        return 1;\n    }\n    else {\n        return 0;\n    }\n}\n/**\n * Run a Promise-returning function on each item in a large list,\n * managed in such a way that <limit> items are pending at any one time.\n *\n * @param list - An array of anything.\n * @param limit - Maximum number of `fn`s to await at the same time.\n * @param fn - (Optionally async) function that is called for each item in the array. Receives the item and the list index (like array.forEach).\n *\n * @returns the return values of each function in the order of the original list.\n */\nfunction forEachQueue(list, limit, fn) {\n    return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {\n        if (list.length === 0) {\n            return resolve([]);\n        }\n        let queued = [];\n        let pending = [];\n        let resolved = [];\n        // Called by a queue item when its promise has resolved.\n        function next(id, result) {\n            return __awaiter(this, void 0, void 0, function* () {\n                // Remove the item with that ID from the pending array.\n                if (id != null) {\n                    const index = pending.findIndex((p) => p.id === id);\n                    pending.splice(index, 1);\n                    resolved.push({ id: id, value: result });\n                    // Done. Sort and return the resolves results.\n                    if (queued.length === 0 && pending.length === 0) {\n                        return resolve(resolved.sort(byIDAsc).map((item) => item.value));\n                    }\n                }\n                // Fill the pending array until we're at the limit again.\n                while (queued.length > 0 && pending.length < limit) {\n                    const { id, item } = queued.shift();\n                    const result = fn(item, id);\n                    let promise;\n                    // Wrap result in promise if the function didn't return one.\n                    if (result instanceof Promise) {\n                        promise = result;\n                    }\n                    else {\n                        promise = Promise.resolve(result);\n                    }\n                    pending.push({\n                        id,\n                        promise: promise.then((value) => next(id, value)),\n                    });\n                }\n            });\n        }\n        // Fill the queued array with the list items.\n        for (let i = 0; i < list.length; i++) {\n            const item = list[i];\n            queued.push({\n                id: i,\n                item,\n            });\n        }\n        // Call next without an ID to fill the pending array.\n        yield next();\n    }));\n}\nexports.default = forEachQueue;\n"]}