import type { Concurrency } from "@effect/io/Concurrency" import type { Effect } from "@effect/io/Effect" import * as core from "@effect/io/internal/core" /** @internal */ export const match: ( options: { readonly concurrency?: Concurrency } | undefined, sequential: () => Effect, unbounded: () => Effect, bounded: (limit: number) => Effect ) => Effect = ( options: { readonly concurrency?: Concurrency } | undefined, sequential: () => Effect, unbounded: () => Effect, bounded: (limit: number) => Effect ) => { switch (options?.concurrency) { case undefined: { return sequential() } case "unbounded": { return unbounded() } case "inherit": { return core.fiberRefGetWith( core.currentConcurrency, (concurrency) => concurrency === "unbounded" ? unbounded() : concurrency > 1 ? bounded(concurrency) : sequential() ) } default: { return options!.concurrency > 1 ? bounded(options!.concurrency) : sequential() } } } /** @internal */ export const matchSimple: ( options: { readonly concurrency?: Concurrency } | undefined, sequential: () => Effect, concurrent: () => Effect ) => Effect = ( options: { readonly concurrency?: Concurrency } | undefined, sequential: () => Effect, concurrent: () => Effect ) => { switch (options?.concurrency) { case undefined: { return sequential() } case "unbounded": { return concurrent() } case "inherit": { return core.fiberRefGetWith( core.currentConcurrency, (concurrency) => concurrency === "unbounded" ? concurrent() : concurrency > 1 ? concurrent() : sequential() ) } default: { return options!.concurrency > 1 ? concurrent() : sequential() } } }