function / @typed/fx

Subject.hold

Shares an Fx and immediately replays its latest success or failure to each new subscriber.

Package version
2.0.0-beta.13
Category
Sharing sources
Since
1.0.0
Member of
Subject

Import

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

Access Subject.hold 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 hold<A, E, R>(fx: Fx.Fx<A, E, R>): Fx.Fx<A, E, R | Scope.Scope>;

Why

hold gives late subscribers the current publication without restarting an already active source, making it suitable for current-value streams and state-like projections.

Ownership and lifetime

One retained Exit belongs to the active shared subject. The first subscriber starts the source, the last subscriber interrupts it, and interruption clears the retained exit. Source errors and services remain visible in the returned Fx; subscription cleanup belongs to Scope.

Join-during-publication behavior

The latest Exit is retained before it enters the serialized publication queue. If a subscriber joins while an earlier publication is still draining, it can receive that queued exit immediately as replay and then receive it again when the queue reaches it. Consumers that require exactly-once delivery across concurrent subscription and publication must coordinate that boundary externally.

Examples

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

const currentStatus = Subject.hold(Fx.succeed("ready"))

Other public imports

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

Source