variable / @typed/fx/Fx

fork

Forks the execution of an Fx into a background fiber. The stream will run until it completes or the fiber is interrupted.

Package version
2.0.0-beta.13
Category
Running effects
Since
1.0.0

Follow one execution

Start draining in a supervised child fiber; return its Fiber before the source finishes. Parent termination interrupts it.

Fx timelinefork(source)fork
Operatorfork(source)
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.

The returned Effect acquires the source services and creates a child attached to the calling fiber’s scope. Parent termination interrupts the child. By default the child starts immediately and remains interruptible; options can change those two Effect fiber policies. Values are discarded and source failure is reported by the child fiber.

Source implementation · Learn the surrounding model

Compare all Fx timelines →

Import

import { fork } from "@typed/fx/Fx";

Signatures

export declare const fork: <A, E, R>(fx: Fx<A, E, R>, options?: {
    readonly startImmediately?: boolean;
    readonly uninterruptible?: boolean;
}) => Effect<Fiber<unknown, E>, never, R>;

Why

fork keeps background execution inside Effect’s supervised fiber tree while returning an explicit handle for coordination.

Ownership and lifetime

The returned Effect acquires the source services and creates a child attached to the calling fiber’s scope. Parent termination interrupts the child. By default the child starts immediately and remains interruptible; options can change those two Effect fiber policies. Values are discarded and source failure is reported by the child fiber.

Examples

import { Effect, Fiber } from "effect"
import { fork, periodic } from "@typed/fx/Fx"

const program = Effect.gen(function* () {
  const fiber = yield* fork(periodic("1 second"))
  return yield* Fiber.interrupt(fiber)
})

Other public imports

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

Source