// ets_tracing: off import type * as Chunk from "../Collections/Immutable/Chunk/index.js" import type { SortedSet } from "../Collections/Immutable/SortedSet/index.js" import * as Fiber from "../Fiber/index.js" import { pipe } from "../Function/index.js" import { track } from "../Supervisor/index.js" import * as core from "./core.js" import type { Effect, RIO } from "./effect.js" import * as ensuring from "./ensuring.js" /** * Acts on the children of this fiber, guaranteeing the specified callback * will be invoked, whether or not this effect succeeds. * * @ets_data_first ensuringChildren_ */ export function ensuringChildren( children: (_: SortedSet>) => RIO, __trace?: string ) { return (fa: Effect): Effect => ensuringChildren_(fa, children, __trace) } /** * Acts on the children of this fiber, guaranteeing the specified callback * will be invoked, whether or not this effect succeeds. */ export function ensuringChildren_( fa: Effect, children: (_: SortedSet>) => RIO, __trace?: string ) { return pipe( track, core.chain((s) => pipe( fa, core.supervised(s), ensuring.ensuring(pipe(s.value, core.chain(children)), __trace) ) ) ) } /** * Acts on the children of this fiber (collected into a single fiber), * guaranteeing the specified callback will be invoked, whether or not * this effect succeeds. */ export function ensuringChild_( fa: Effect, f: (_: Fiber.Fiber>) => RIO, __trace?: string ) { return ensuringChildren_(fa, (x) => pipe(x, Fiber.collectAll, f), __trace) } /** * Acts on the children of this fiber (collected into a single fiber), * guaranteeing the specified callback will be invoked, whether or not * this effect succeeds. * * @ets_data_first ensuringChild_ */ export function ensuringChild( f: (_: Fiber.Fiber>) => RIO, __trace?: string ) { return (fa: Effect) => ensuringChild_(fa, f, __trace) }