Genel bakış
functionTiming And Cancellation

retry

Retries a behavior when it returns an expected domain failure.

Signature

tsSignature
export function retry<I, O, E, C extends object>(
source: Behavior<I, O, E, C>,
options: RetryOptions<E>,
): Behavior<I, O, E, C>;

Imports

tsImport
import { retry } from "@/lib/flow/retry";
import { retry } from "@/lib/flow";

Type Parameters

I

Source input type.

O

Source output type.

E

Source domain error type.

C

Custom context type.

Parameters

source
Behavior<I, O, E, C>

Behavior to retry.

options

Retry attempts, optional delay, and optional predicate.

Returns

A behavior with the same success and domain error types as the source.

Return type
Behavior<I, O, E, C>

Details

The source is run at most `options.attempts` times. Runtime errors and cancellation return

immediately. Cancellation during a retry delay returns `Cancelled`.

Examples

tsExample
const resilientLoad = retry(loadUser, {
attempts: 3,
delay: (attempt) => attempt * 100,
when: (error) => error.kind === "rate-limited",
});
Behavior

Executable Flow workflow unit.

type
delay

Waits before running a source behavior.

function
RetryOptions

Configuration for retrying expected domain failures.

type
run

Runs a behavior with an optional application context.

function

Source

tsflow/retry.ts:61-66
export function retry<I, O, E, C extends object>(
source: Behavior<I, O, E, C>,
options: RetryOptions<E>,
): Behavior<I, O, E, C> {
return retryBehavior(source, retryPolicy(options));
}