function / @typed/fx

Sink.withEarlyExit

Runs a producer-style callback with a sink that can complete the surrounding Effect early.

Package version
2.0.0-beta.7
Category
Stopping delivery
Since
1.0.0
Member of
Sink

Import

import { Sink } from "@typed/fx";

Access Sink.withEarlyExit through the imported Sink export. Its declaration below describes the member.

This public exposure is a re-export. Its import path is supported; declaration documentation is shared with the other public exposures below.

Signatures

export declare function withEarlyExit<A, E, R, R2>(sink: Sink<A, E, R>, f: (sink: Sink.WithEarlyExit<A, E, R>, params: {
    signal: AbortSignal;
    scheduler: Scheduler;
}) => Effect.Effect<unknown, never, R2>): Effect.Effect<void, never, R | R2>;

Why

Consumer combinators can stop upstream work after a bound or predicate without representing normal completion as failure.

Ownership and lifetime

The returned Effect owns the callback fiber. Completion, earlyExit, or interruption aborts that fiber through the supplied signal; deliveries after exit are ignored. The callback’s services are combined with the wrapped sink’s services.

Examples

import { Effect } from "effect"
import * as Sink from "@typed/fx/Sink"
const base = Sink.make(Effect.logError, Effect.log)
const program = Sink.withEarlyExit(base, (sink) => sink.onSuccess("done").pipe(Effect.andThen(sink.earlyExit)))

Other public imports

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

Source