Hyperlinkv0.8.0-beta.28

Layer

Layer.tapCauseconsteffect/Layer.ts:1716
<E, XE extends E, RIn2, E2, X>(
  f: (cause: Cause.Cause<XE>) => Effect<X, E2, RIn2>
): <RIn, ROut>(
  self: Layer<ROut, E, RIn>
) => Layer<ROut, E | E2, RIn | Exclude<RIn2, Scope.Scope>>
<RIn, E, XE extends E, ROut, RIn2, E2, X>(
  self: Layer<ROut, E, RIn>,
  f: (cause: Cause.Cause<XE>) => Effect<X, E2, RIn2>
): Layer<ROut, E | E2, RIn | Exclude<RIn2, Scope.Scope>>

Performs the specified effect when this layer fails with any cause.

When to use

Use to run diagnostics or reporting when layer construction fails and the full Cause is needed.

Details

The callback receives the layer's Cause, so it can inspect typed errors, defects, and interruption information. If the callback succeeds, the layer fails again with the original cause; if the callback fails, that failure is added to the layer's error type.

Source effect/Layer.ts:171619 lines
export const tapCause: {
  <E, XE extends E, RIn2, E2, X>(
    f: (cause: Cause.Cause<XE>) => Effect<X, E2, RIn2>
  ): <RIn, ROut>(self: Layer<ROut, E, RIn>) => Layer<ROut, E | E2, RIn | Exclude<RIn2, Scope.Scope>>
  <RIn, E, XE extends E, ROut, RIn2, E2, X>(
    self: Layer<ROut, E, RIn>,
    f: (cause: Cause.Cause<XE>) => Effect<X, E2, RIn2>
  ): Layer<ROut, E | E2, RIn | Exclude<RIn2, Scope.Scope>>
} = dual(2, <RIn, E, XE extends E, ROut, RIn2, E2, X>(
  self: Layer<ROut, E, RIn>,
  f: (cause: Cause.Cause<XE>) => Effect<X, E2, RIn2>
): Layer<ROut, E | E2, RIn | Exclude<RIn2, Scope.Scope>> =>
  fromBuild((memoMap, scope) =>
    internalEffect.catchCause(
      self.build(memoMap, scope),
      (cause) =>
        Scope.provide(internalEffect.andThen(f(cause as Cause.Cause<XE>), internalEffect.failCause(cause)), scope)
    )
  ))