"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.collectAll = collectAll;

var tsplus_module_1 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/FiberId/operations/none"));

var tsplus_module_2 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Fiber/operations/id"));

var tsplus_module_3 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/FiberId/operations/combine"));

var tsplus_module_4 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/collections/Collection/functions"));

var tsplus_module_5 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Effect/operations/done"));

var tsplus_module_6 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Fiber/operations/await"));

var tsplus_module_7 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Effect/operations/flatMap"));

var tsplus_module_8 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Effect/operations/excl-forEach"));

var tsplus_module_9 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Effect/operations/exit"));

var tsplus_module_10 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/collections/Chunk/flatten"));

var tsplus_module_11 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Fiber/operations/children"));

var tsplus_module_12 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Effect/operations/map"));

var tsplus_module_13 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Fiber/operations/inheritRefs"));

var tsplus_module_14 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/collections/Chunk/empty"));

var tsplus_module_15 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Exit/operations/succeed"));

var tsplus_module_16 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/data/Maybe/definition"));

var tsplus_module_17 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/collections/Chunk/prepend"));

var tsplus_module_18 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Cause/definition"));

var tsplus_module_19 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Exit/operations/zipWith"));

var tsplus_module_20 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/data/Maybe/fold"));

var tsplus_module_21 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/collections/Chunk/reduceRight"));

var tsplus_module_22 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Fiber/operations/poll"));

var tsplus_module_23 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Fiber/operations/interruptAs"));

var _definition3 = /*#__PURE__*/require("@effect/core/io/Fiber/definition");

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

const fileName_1 = "(@effect/core) _src/io/Fiber/operations/collectAll.ts";

/**
 * Collects all fibers into a single fiber producing an in-order list of the
 * results.
 *
 * @tsplus static ets/Fiber/Ops collectAll
 */
function collectAll(fibers) {
  return (0, _definition3.makeSynthetic)({
    id: tsplus_module_4.reduce_(fibers, tsplus_module_1.none, (id, fiber) => tsplus_module_3.combine_(id, tsplus_module_2.id(fiber))),
    await: tsplus_module_9.exit(tsplus_module_8.forEachPar(() => fibers, fiber => tsplus_module_7.flatMap_(tsplus_module_6._await(fiber, fileName_1 + ":12:60"), _ => tsplus_module_5.done(() => _, fileName_1 + ":12:89"), fileName_1 + ":12:70"), fileName_1 + ":12:29"), fileName_1 + ":12:99"),
    children: tsplus_module_12.map_(tsplus_module_8.forEachPar(() => fibers, fiber => tsplus_module_11.children(fiber, fileName_1 + ":13:66"), fileName_1 + ":13:32"), _ => tsplus_module_10.flatten(_), fileName_1 + ":13:73"),
    inheritRefs: tsplus_module_8.forEachDiscard(() => fibers, fiber => tsplus_module_13.inheritRefs(fiber, fileName_1 + ":14:76"), fileName_1 + ":14:39"),
    poll: tsplus_module_12.map_(tsplus_module_8.forEach(() => fibers, fiber => tsplus_module_22.poll(fiber, fileName_1 + ":15:55"), fileName_1 + ":15:25"), chunk => tsplus_module_21.reduceRight_(chunk, tsplus_module_16.some(tsplus_module_15.succeed(tsplus_module_14.empty())), (a, b) => tsplus_module_20.fold_(a, () => tsplus_module_16.none, ra => tsplus_module_20.fold_(b, () => tsplus_module_16.none, rb => tsplus_module_16.some(tsplus_module_19.zipWith_(ra, rb, (_a, _b) => tsplus_module_17.prepend_(_b, _a), tsplus_module_18.combinePar))))), fileName_1 + ":15:62"),
    interruptAs: fiberId => tsplus_module_12.map_(tsplus_module_8.forEach(() => fibers, fiber => tsplus_module_23.interruptAsNow_(fiber, fiberId, fileName_1 + ":30:58"), fileName_1 + ":30:21"), _ => tsplus_module_21.reduceRight_(_, tsplus_module_15.succeed(tsplus_module_14.empty()), (a, b) => tsplus_module_19.zipWith_(a, b, (_a, _b) => tsplus_module_17.prepend_(_b, _a), tsplus_module_18.combinePar)), fileName_1 + ":30:72")
  });
}
//# sourceMappingURL=collectAll.js.map