Обзор
functionTiming And Cancellation

delay

Waits before running a source behavior.

Signature

tsSignature
export function delay<I, O, E, C extends object>(
source: Behavior<I, O, E, C>,
ms: number,
): Behavior<I, O, E | TimingError, C>;

Imports

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

Type Parameters

I

Input type.

O

Source output type.

E

Source domain error type.

C

Custom context type.

Parameters

source
Behavior<I, O, E, C>

Behavior to run after the delay.

ms
number

Delay in milliseconds before source execution.

Returns

A behavior with the source result or timing errors.

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

Details

`delay` models a pause that is part of the workflow itself. Cancellation during the delay returns

a timing cancellation error and the source behavior is not started.

Examples

tsExample
const delayedLoad = delay(loadUser, 250);
Behavior

Executable Flow workflow unit.

type

Source

tsflow/delay.ts:24-41
export function delay<I, O, E, C extends object>(
source: Behavior<I, O, E, C>,
ms: number,
): Behavior<I, O, E | TimingError, C> {
return async (input: I, context: RuntimeContext<C>) => {
if (context.signal.aborted) {
return resultFromSignal(context.signal);
}
const delayResult = await wait(ms, context.signal);
if (!delayResult.ok) {
return delayResult;
}
return runBehavior(source, input, context);
};
}