Follow one execution
Builds a Layer for each subscription and provides it to the entire Fx run.
provideTick 0. Service Layer: start.
Read this diagram
Follow each lane from left to right. Events stacked vertically share a tick; the green cursor marks the current time across every lane.
- A value
The text inside the pill is the emitted value. - Work starts
The raised chevron starts an inner run (^in the source). - The run returns
The vertical bar ends this lane’s run. - A cause is delivered
The exclamation mark belongs to this lane. - Work is interrupted
The cross marks cancellation of this run. - Current time
The line and diamond move together across all lanes. - Happening now
A highlighted event is at the current tick. - Still ahead
Muted, dashed values have not happened yet. - Time continues
The lane’s arrow is not a return marker. An empty stretch can be quiet work that is still running.
Illustrated ticks start at 0. At 1×, one illustrated tick takes one second; captions specify real durations when timing matters. A cause or interruption belongs to its lane, and other work may continue. Scroll horizontally to inspect the rest of a long timeline.
Each subscription creates a private Scope and builds the Layer inside it before the source starts. A build failure is sent to the sink and the source never runs. Otherwise the built Context is available to every source Effect, and the Scope closes with the source’s success, failure, defect, or interruption. Provided services are removed from R; Layer dependencies and errors are added.
Import
import { Fx } from "@typed/fx";Access Fx.provide through the imported Fx 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 const provide: {
<R2, E2 = never, R3 = never>(layer: Layer.Layer<R2, E2, R3>): <A, E, R>(fx: Fx<A, E, R>) => Fx<A, E | E2, Exclude<R, R2> | R3>;
<A, E, R, R2, E2 = never, R3 = never>(fx: Fx<A, E, R>, layer: Layer.Layer<R2, E2, R3>): Fx<A, E | E2, Exclude<R, R2> | R3>;
};Why
Fx preserves Effect service requirements in R; providing a Layer closes
those requirements while retaining acquisition failures and dependencies in
the resulting type.
Ownership and lifetime
Each subscription creates a private Scope and builds the Layer inside it
before the source starts. A build failure is sent to the sink and the source
never runs. Otherwise the built Context is available to every source Effect,
and the Scope closes with the source’s success, failure, defect, or
interruption. Provided services are removed from R; Layer dependencies and
errors are added.
Examples
import { Context, Effect, Layer } from "effect"
import { provide } from "@typed/fx/Fx"
import { fromEffect } from "@typed/fx/Fx"
class Config extends Context.Service<Config, { readonly url: string }>()("Config") {}
const request = fromEffect(Effect.map(Config, ({ url }) => url))
const runnable = provide(request, Layer.succeed(Config, { url: "/api" }))Other public imports
These import paths expose the same declaration. Each page retains its own public name and signature.