| 39 | |
| 40 | /** @internal */ |
| 41 | export const acquireUseRelease = <Acquired, OutErr, Env, OutElem1, InElem, InErr, OutDone, InDone>( |
| 42 | acquire: Effect.Effect<Acquired, OutErr, Env>, |
| 43 | use: (a: Acquired) => Channel.Channel<OutElem1, InElem, OutErr, InErr, OutDone, InDone, Env>, |
| 44 | release: (a: Acquired, exit: Exit.Exit<OutDone, OutErr>) => Effect.Effect<any, never, Env> |
| 45 | ): Channel.Channel<OutElem1, InElem, OutErr, InErr, OutDone, InDone, Env> => |
| 46 | core.flatMap( |
| 47 | core.fromEffect( |
| 48 | Ref.make< |
| 49 | (exit: Exit.Exit<OutDone, OutErr>) => Effect.Effect<any, never, Env> |
| 50 | >(() => Effect.void) |
| 51 | ), |
| 52 | (ref) => |
| 53 | pipe( |
| 54 | core.fromEffect( |
| 55 | Effect.uninterruptible( |
| 56 | Effect.tap( |
| 57 | acquire, |
| 58 | (a) => Ref.set(ref, (exit) => release(a, exit)) |
| 59 | ) |
| 60 | ) |
| 61 | ), |
| 62 | core.flatMap(use), |
| 63 | core.ensuringWith((exit) => Effect.flatMap(Ref.get(ref), (f) => f(exit))) |
| 64 | ) |
| 65 | ) |
| 66 | |
| 67 | /** @internal */ |
| 68 | export const as = dual< |