function / @typed/fx/Subject

make

Acquires a Subject whose subscribers and replay state are released with the current Scope.

Package version
2.0.0-beta.7
Category
Subject construction
Since
1.0.0

Import

import { make } from "@typed/fx/Subject";

Signatures

export declare function make<A, E = never>(replay?: number): Effect.Effect<Subject<A, E>, Cause.IllegalArgumentError, Scope.Scope>;

Why

make places the imperative subject boundary under Effect’s structured resource ownership, so cancellation and scope closure cannot leave subscriptions or retained values behind.

Ownership and lifetime

The effect allocates when executed, not when described. Its required Scope installs a finalizer that runs interrupt, closing all subscriber scopes and clearing the replay buffer. Individual subscriber scopes may still end earlier without affecting other subscribers.

Errors

Invalid capacities fail in the typed error channel with Cause.IllegalArgumentError; no subject is allocated. Once acquired, publication callbacks have no typed failure result; the subject’s E parameter describes incoming Causes rather than publication acknowledgment errors. Interruption and defects remain distinct from that typed channel.

Examples

import { Effect } from "effect"
import * as Subject from "@typed/fx/Subject"

const program = Effect.gen(function* () {
  const messages = yield* Subject.make<string>(1)
  yield* messages.onSuccess("online")
  return yield* messages.subscriberCount
}).pipe(Effect.scoped)

Other public imports

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

Source