( finalizer: (exit: Exit.Exit<unknown, unknown>) => Effect.Effect<X, never, R> )
| 1708 | |
| 1709 | /* @internal */ |
| 1710 | export const addFinalizer = <X, R>( |
| 1711 | finalizer: (exit: Exit.Exit<unknown, unknown>) => Effect.Effect<X, never, R> |
| 1712 | ): Effect.Effect<void, never, R | Scope.Scope> => |
| 1713 | core.withFiberRuntime( |
| 1714 | (runtime) => { |
| 1715 | const acquireRefs = runtime.getFiberRefs() |
| 1716 | const acquireFlags = runtimeFlags_.disable(runtime.currentRuntimeFlags, runtimeFlags_.Interruption) |
| 1717 | return core.flatMap(scope, (scope) => |
| 1718 | core.scopeAddFinalizerExit(scope, (exit) => |
| 1719 | core.withFiberRuntime((runtimeFinalizer) => { |
| 1720 | const preRefs = runtimeFinalizer.getFiberRefs() |
| 1721 | const preFlags = runtimeFinalizer.currentRuntimeFlags |
| 1722 | const interruptedCause = preRefs.locals.get(core.currentInterruptedCause) |
| 1723 | const locals = new Map(acquireRefs.locals) |
| 1724 | if (interruptedCause === undefined) { |
| 1725 | locals.delete(core.currentInterruptedCause) |
| 1726 | } else { |
| 1727 | locals.set(core.currentInterruptedCause, interruptedCause) |
| 1728 | } |
| 1729 | const refs = fiberRefs.unsafeMake(locals) |
| 1730 | const patchFlags = runtimeFlags_.diff(preFlags, acquireFlags) |
| 1731 | const inverseRefs = FiberRefsPatch.diff(refs, preRefs) |
| 1732 | runtimeFinalizer.setFiberRefs(refs) |
| 1733 | |
| 1734 | return ensuring( |
| 1735 | core.withRuntimeFlags( |
| 1736 | core.suspend(() => |
| 1737 | finalizer(exit) as Effect.Effect<X> |
| 1738 | ), |
| 1739 | patchFlags |
| 1740 | ), |
| 1741 | core.sync(() => { |
| 1742 | runtimeFinalizer.setFiberRefs( |
| 1743 | FiberRefsPatch.patch(inverseRefs, runtimeFinalizer.id(), runtimeFinalizer.getFiberRefs()) |
| 1744 | ) |
| 1745 | }) |
| 1746 | ) |
| 1747 | }))) |
| 1748 | } |
| 1749 | ) |
| 1750 | |
| 1751 | /* @internal */ |
| 1752 | export const daemonChildren = <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> => { |
no test coverage detected