25 lines
18 KiB
JavaScript
Raw Normal View History

"use strict";
/*
* ATTENTION: An "eval-source-map" devtool has been used.
* This devtool is neither made for production nor for readable output files.
* It uses "eval()" calls to create a separate source file with attached SourceMaps in the browser devtools.
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
* or disable the default devtool with "devtool: false".
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
*/
exports.id = "vendor-chunks/it-parallel";
exports.ids = ["vendor-chunks/it-parallel"];
exports.modules = {
/***/ "(ssr)/./node_modules/it-parallel/dist/src/index.js":
/*!****************************************************!*\
!*** ./node_modules/it-parallel/dist/src/index.js ***!
\****************************************************/
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ parallel)\n/* harmony export */ });\n/* harmony import */ var p_defer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! p-defer */ \"(ssr)/./node_modules/p-defer/index.js\");\n/**\n * @packageDocumentation\n *\n * Takes an (async) iterable that emits promise-returning functions, invokes them in parallel up to the concurrency limit and emits the results as they become available, optionally in the same order as the input\n *\n * @example\n *\n * ```javascript\n * import parallel from 'it-parallel'\n * import all from 'it-all'\n * import delay from 'delay'\n *\n * // This can also be an iterator, async iterator, generator, etc\n * const input = [\n * async () => {\n * console.info('start 1')\n * await delay(500)\n *\n * console.info('end 1')\n * return 1\n * },\n * async () => {\n * console.info('start 2')\n * await delay(200)\n *\n * console.info('end 2')\n * return 2\n * },\n * async () => {\n * console.info('start 3')\n * await delay(100)\n *\n * console.info('end 3')\n * return 3\n * }\n * ]\n *\n * const result = await all(parallel(input, {\n * concurrency: 2\n * }))\n *\n * // output:\n * // start 1\n * // start 2\n * // end 2\n * // start 3\n * // end 3\n * // end 1\n *\n * console.info(result) // [2, 3, 1]\n * ```\n *\n * If order is important, pass `ordered: true` as an option:\n *\n * ```javascript\n * const result = await all(parallel(input, {\n * concurrency: 2,\n * ordered: true\n * }))\n *\n * // output:\n * // start 1\n * // start 2\n * // end 2\n * // start 3\n * // end 3\n * // end 1\n *\n * console.info(result) // [1, 2, 3]\n * ```\n */ \nconst CustomEvent = globalThis.CustomEvent ?? Event;\n/**\n * Takes an (async) iterator that emits promise-returning functions,\n * invokes them in parallel and emits the results as they become available but\n * in the same order as the input\n */ async function* parallel(source, options = {}) {\n let concurrency = options.concurrency ?? Infinity;\n if (concurrency < 1) {\n concurrency = Infinity;\n }\n const ordered = options.ordered == null ? false : options.ordered;\n const emitter = new EventTarget();\n const ops = [];\n let slotAvailable = (0,p_defer__WEBPACK_IMPORTED_MODULE_0__[\"default\"])();\n let resultAvailable = (0,p_defer__WEBPACK_IMPORTED_MODULE_0__[\"default\"])();\n let sourceFinished = false;\n let sourceErr;\n let opErred = false;\n emitter.addEventListener(\"task-complete\", ()=>{\n resultAvailable.resolve();\n });\n void Promise.resolve().then(async ()=>{\n try {\n for await (const task of source){\n if (ops.length === concurrency) {\n slotAvailable = (0,p_defer__WEBPACK_IMPORTED_MODULE_0__[\"default\"])();\n await slotAvailable.promise;\n }\n if (opErred) {\n break;\n }\n const op = {\n done: false\n };\n ops.push(op);\n task().then((result)=>{\n op.done = true;\n op.ok = true;\n op.value = result;\n emitter.dispatchEvent(new CustomEvent(\"task-complete\"));\n }, (err)=>{\n op.done = true;\n op.err = err;\n emitter.dispatchEvent(new CustomEvent(\"task-complete\"));\n });\n }\n sourceFinished = true;\n emitter.dispatchEvent(new CustomEvent(\"task-complete\"));\n } catch (err) {\n sourceErr = err;\n emitter.dispatchEvent(new CustomEvent(\"task-complete\"));\n }\n });\n function valuesAvailable() {\n if (ordered) {\n return ops[0]?.done;\n }\n return Boolean(ops.find((op)=>op.done))
/***/ })
};
;