variable / @typed/fx

Fx.delay

Sleeps for duration before forwarding each successful source delivery.

Package version
2.0.0-beta.13
Category
Time and rate
Since
1.0.0
Member of
Fx

Follow one execution

Sleeps for duration before forwarding each value; the diagram shows serial delivery.

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.

This uses mapEffect and inherits producer concurrency. A serial producer waits for each delayed delivery; concurrent deliveries can overlap their sleeps. No queue or ordering guarantee is added. Source failures propagate and interruption cancels active sleeps.

Source implementation · Learn the surrounding model

Compare all Fx timelines →

Import

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

Access Fx.delay 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 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