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.13
Category
Subject construction
Since
1.0.0
Member of
Subject

Import

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

Access Subject.make through the imported Subject 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 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