variable / @typed/template/EventHandler

catchCause

Recovers from errors in the EventHandler.

Package version
1.0.0-beta.13
Category
Handler failure recovery
Since
1.0.0

Import

import { catchCause } from "@typed/template/EventHandler";

Signatures

export declare const catchCause: {
    <E, E2 = never, R2 = never>(f: (cause: Cause.Cause<E>) => Effect.Effect<unknown, E2, R2>): <Ev extends Event, R = never>(handler: EventHandler<Ev, E, R>) => EventHandler<Ev, E2, R | R2>;
    <Ev extends Event, E = never, R = never, E2 = never, R2 = never>(handler: EventHandler<Ev, E, R>, f: (cause: Cause.Cause<E>) => Effect.Effect<unknown, E2, R2>): EventHandler<Ev, E2, R | R2>;
};

Why

Handling the full Cause preserves interruption and defect information instead of reducing failures to thrown exceptions.

Ownership and lifetime

The returned description installs no listener. Recovery runs in the same handler fiber and mount Scope when a real event arrives.

Examples

import { Effect } from "effect"
import * as EventHandler from "@typed/template/EventHandler"

const handler = EventHandler.make((event) =>
  Effect.fail("Something went wrong")
)

// Recover from errors
const recovered = EventHandler.catchCause(handler, (cause) =>
  Effect.sync(() => console.error("Error:", cause))
)

Other public imports

These import paths expose the same declaration. Each page retains its own public name and signature.

Source