variable / @typed/fx

Fx.retry

Retries the entire stream when its Cause contains a typed Fail accepted by schedule.

The schedule is reset as soon as the first element of an attempt is emitted, matching Effect Stream.retry.

Package version
2.0.0-beta.13
Category
Errors and recovery
Since
1.0.0
Member of
Fx

Follow one execution

Retries the entire stream when its Cause contains a typed Fail accepted by schedule. The schedule is reset as soon as the first element of an attempt is emitted, matching Effect Stream.retry.

Fx timelineretry retains prior deliveries and resubscribes after a typed failureretry
Operatorretry(Schedule.recurs(1))
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.

Attempts are sequential and reuse the same downstream sink. The first Fail found anywhere in the Cause is offered to the Schedule, so a composite Cause containing that Fail can be retried even when it also contains defects or interrupts; starting a new attempt discards the whole prior Cause. A Cause without a Fail terminates immediately. Schedule completion re-emits the last source Cause, while Schedule failure terminates with its own cause. Emitting any value resets the Schedule. External interruption cancels the active attempt or backoff sleep.

Source implementation · Learn the surrounding model

Compare all Fx timelines →

Import

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

Access Fx.retry 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 retry: {
    <E, X, E2, R2>(schedule: Schedule.Schedule<X, E, E2, R2>): <A, R>(self: Fx<A, E, R>) => Fx<A, E | E2, R | R2>;
    <A, E, R, X, E2, R2>(self: Fx<A, E, R>, schedule: Schedule.Schedule<X, E, E2, R2>): Fx<A, E | E2, R | R2>;
};

Why

Retrying the whole producer, rather than a single value callback, gives a Schedule the typed failure that ended an attempt and lets it control backoff.

Ownership and lifetime

Attempts are sequential and reuse the same downstream sink. The first Fail found anywhere in the Cause is offered to the Schedule, so a composite Cause containing that Fail can be retried even when it also contains defects or interrupts; starting a new attempt discards the whole prior Cause. A Cause without a Fail terminates immediately. Schedule completion re-emits the last source Cause, while Schedule failure terminates with its own cause. Emitting any value resets the Schedule. External interruption cancels the active attempt or backoff sleep.

Examples

import { Schedule } from "effect"
import { retry } from "@typed/fx/Fx"
import { fail } from "@typed/fx/Fx"

const retried = retry(fail("offline"), Schedule.recurs(2))
A composite Cause is retryable when it contains a Fail
```ts
import { Cause, Schedule } from "effect"
import { retry } from "@typed/fx/Fx"
import { failCause } from "@typed/fx/Fx"

const composite = Cause.combine(Cause.fail("offline"), Cause.die("decoder defect"))
const retried = retry(failCause(composite), Schedule.recurs(2))
```

Other public imports

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

Source