const fileName_1 = "(@effect/core) _src/io/Fiber/operations/collectAll.ts";
import * as tsplus_module_1 from "@effect/core/io/FiberId/operations/none";
import * as tsplus_module_2 from "@effect/core/io/Fiber/operations/id";
import * as tsplus_module_3 from "@effect/core/io/FiberId/operations/combine";
import * as tsplus_module_4 from "@tsplus/stdlib/collections/Collection/functions";
import * as tsplus_module_5 from "@effect/core/io/Effect/operations/done";
import * as tsplus_module_6 from "@effect/core/io/Fiber/operations/await";
import * as tsplus_module_7 from "@effect/core/io/Effect/operations/flatMap";
import * as tsplus_module_8 from "@effect/core/io/Effect/operations/excl-forEach";
import * as tsplus_module_9 from "@effect/core/io/Effect/operations/exit";
import * as tsplus_module_10 from "@tsplus/stdlib/collections/Chunk/flatten";
import * as tsplus_module_11 from "@effect/core/io/Fiber/operations/children";
import * as tsplus_module_12 from "@effect/core/io/Effect/operations/map";
import * as tsplus_module_13 from "@effect/core/io/Fiber/operations/inheritRefs";
import * as tsplus_module_14 from "@tsplus/stdlib/collections/Chunk/empty";
import * as tsplus_module_15 from "@effect/core/io/Exit/operations/succeed";
import * as tsplus_module_16 from "@tsplus/stdlib/data/Maybe/definition";
import * as tsplus_module_17 from "@tsplus/stdlib/collections/Chunk/prepend";
import * as tsplus_module_18 from "@effect/core/io/Cause/definition";
import * as tsplus_module_19 from "@effect/core/io/Exit/operations/zipWith";
import * as tsplus_module_20 from "@tsplus/stdlib/data/Maybe/fold";
import * as tsplus_module_21 from "@tsplus/stdlib/collections/Chunk/reduceRight";
import * as tsplus_module_22 from "@effect/core/io/Fiber/operations/poll";
import * as tsplus_module_23 from "@effect/core/io/Fiber/operations/interruptAs";
import { makeSynthetic } from "@effect/core/io/Fiber/definition";
/**
 * Collects all fibers into a single fiber producing an in-order list of the
 * results.
 *
 * @tsplus static ets/Fiber/Ops collectAll
 */

export function collectAll(fibers) {
  return 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.mjs.map