MCPcopy
hub / github.com/Effect-TS/effect / addFinalizer

Function addFinalizer

packages/effect/src/internal/fiberRuntime.ts:1710–1739  ·  view source on GitHub ↗
(
  finalizer: (exit: Exit.Exit<unknown, unknown>) => Effect.Effect<X, never, R>
)

Source from the content-addressed store, hash-verified

1708
1709/* @internal */
1710export 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 */
1742export const daemonChildren = <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> => {

Callers 2

fiberRuntime.tsFile · 0.70
withRuntimeFlagsScopedFunction · 0.70

Calls 9

finFunction · 0.85
setFiberRefsMethod · 0.80
syncMethod · 0.80
finalizerFunction · 0.70
getFiberRefsMethod · 0.65
diffMethod · 0.65
patchMethod · 0.65
idMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…