( 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 patchRefs = FiberRefsPatch.diff(preRefs, acquireRefs) |
| 1723 | const patchFlags = runtimeFlags_.diff(preFlags, acquireFlags) |
| 1724 | const inverseRefs = FiberRefsPatch.diff(acquireRefs, preRefs) |
| 1725 | runtimeFinalizer.setFiberRefs( |
| 1726 | FiberRefsPatch.patch(patchRefs, runtimeFinalizer.id(), acquireRefs) |
| 1727 | ) |
| 1728 | |
| 1729 | return ensuring( |
| 1730 | core.withRuntimeFlags(finalizer(exit) as Effect.Effect<X>, patchFlags), |
| 1731 | core.sync(() => { |
| 1732 | runtimeFinalizer.setFiberRefs( |
| 1733 | FiberRefsPatch.patch(inverseRefs, runtimeFinalizer.id(), runtimeFinalizer.getFiberRefs()) |
| 1734 | ) |
| 1735 | }) |
| 1736 | ) |
| 1737 | }))) |
| 1738 | } |
| 1739 | ) |
| 1740 | |
| 1741 | /* @internal */ |
| 1742 | export const daemonChildren = <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> => { |
no test coverage detected
searching dependent graphs…