// ets_tracing: off import * as Tp from "../Collections/Immutable/Tuple/index.js" import { pipe } from "../Function/index.js" import * as T from "./deps-core.js" import { managedApply } from "./managed.js" import * as add from "./ReleaseMap/add.js" import type { ReleaseMap } from "./ReleaseMap/index.js" /** * Lifts a `Effect< R, E, A>` into `Managed< R, E, A>` with a release action * that handles `Exit`. The acquire and release actions will be performed uninterruptibly. * * @ets_data_first makeExit_ */ export function makeExit( release: (a: A, exit: T.Exit) => T.Effect, __trace?: string ) { return (acquire: T.Effect) => makeExit_(acquire, release, __trace) } /** * Lifts a `Effect< R, E, A>` into `Managed< R, E, A>` with a release action * that handles `Exit`. The acquire and release actions will be performed uninterruptibly. */ export function makeExit_( acquire: T.Effect, release: (a: A, exit: T.Exit) => T.Effect, __trace?: string ) { return managedApply( T.uninterruptible( pipe( T.do, T.bind("r", () => T.environment>()), T.bind("a", (s) => T.provideAll_(acquire, s.r.get(0)), __trace), T.bind("rm", (s) => add.add((ex) => T.provideAll_(release(s.a, ex), s.r.get(0), __trace))( s.r.get(1) ) ), T.map((s) => Tp.tuple(s.rm, s.a)) ) ) ) }