Import
import { Sink } from "@typed/fx";Access Sink.withStateSemaphore 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 withStateSemaphore<A, E, R, B, R2>(sink: Sink<A, E, R>, state: B, f: (sink: Sink.WithStateSemaphore<A, E, R, B>, params: {
signal: AbortSignal;
scheduler: Scheduler;
}) => Effect.Effect<unknown, never, R2>): Effect.Effect<void, never, R | R2>;Why
Overlapping asynchronous callbacks need a lock to prevent multiple updates from reading the same prior state.
Ownership and lifetime
Each execution owns one mutable cell and one single-permit semaphore. Modify Effects serialize in semaphore-acquisition order, release the permit on completion or interruption, and expose their typed errors and services. Constructing an Effect does not acquire the permit; running it does. Exit aborts the surrounding callback fiber.
Examples
import { Effect } from "effect"
import * as Sink from "@typed/fx/Sink"
const base = Sink.make(Effect.logError, Effect.log)
const program = Sink.withStateSemaphore(base, 0, (state) =>
state.updateEffect((n) => Effect.succeed(n + 1)).pipe(Effect.andThen(state.earlyExit)))Other public imports
These import paths expose the same declaration. Each page retains its own public name and signature.