function / @typed/fx

RefSubject.fromEffect

Creates a RefSubject from an Effect.

Package version
2.0.0-beta.7
Category
Source adapters
Since
1.0.0
Member of
RefSubject

Import

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

Access RefSubject.fromEffect through the imported RefSubject 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 fromEffect<A, E, R>(effect: Effect.Effect<A, E, R>, options?: RefSubjectOptions<A>): Effect.Effect<RefSubject<A, E>, never, R | Scope.Scope>;

Why

Makes effect acquisition explicit while normalizing it into current RefSubject state and subsequent pushed versions.

Ownership and lifetime

The creation Effect requires Scope and the source’s services, which it captures for the private initializer Scope. The source Effect itself stays deferred until the first current read or observation and runs at most once. Source failures remain visible on reads and observations; closing the creation Scope interrupts an initializer that is still running.

Examples

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

const program = Effect.gen(function* () {
  const ref = yield* RefSubject.fromEffect(
    Effect.succeed("Initial value")
  )

  const value = yield* ref
  console.log(value) // "Initial value"
})

Other public imports

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

Source