variable / @typed/fx/Fx

delay

Sleeps for duration before forwarding each successful source delivery.

Package version
2.0.0-beta.7
Category
Time and rate
Since
1.0.0

Follow one execution

Delays every source value by duration while preserving its value and order.

Fx timelinedelay shifts every value by 100ms (two 50ms slots)delay
Operatordelay(100ms)
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 delivered value runs an Effect sleep before reaching the sink. Because this uses sequential effectful mapping, later values wait behind earlier sleeps and arrival order is preserved. Source failures propagate; interrupting the subscription interrupts the active sleep. No external resource is retained.

Source implementation · Learn the surrounding model

Compare all Fx timelines →

Import

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

Signatures

export declare const delay: {
    (duration: Duration.Input): <A, E, R>(self: Fx<A, E, R>) => Fx<A, E, R>;
    <A, E, R>(self: Fx<A, E, R>, duration: Duration.Input): Fx<A, E, R>;
};

Why

Per-value delay is useful when pacing downstream work without changing the stream’s error type or replacing the producer.

Ownership and lifetime

Each delivered value runs an Effect sleep before reaching the sink. This uses mapEffect and inherits producer concurrency: a sequential producer waits for each delayed delivery, while concurrent deliveries can overlap their sleeps. No queue or ordering guarantee is added. The source run must await its pending deliveries before normal completion. Source failures propagate; interruption cancels active sleeps. No external resource is retained.

Examples

import { delay } from "@typed/fx/Fx"
import { fromIterable } from "@typed/fx/Fx"

const paced = delay(fromIterable([1, 2, 3]), "100 millis")

Other public imports

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

Source