Обзор
functionTiming And Cancellation

timeout

Wraps a behavior with a timeout.

Signature

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

Imports

tsImport
import { timeout } from "@/lib/flow/timeout";
import { timeout } 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 run with a time limit.

ms
number

Timeout in milliseconds.

Returns

A behavior with the source result or timing errors.

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

Details

The source runs with a child signal linked to the parent. If the timer expires first, the child

is aborted and a timeout domain error is returned.

Examples

tsExample
const boundedLoad = timeout(loadUser, 1000);
Behavior

Executable Flow workflow unit.

type

Source

tsflow/timeout.ts:46-51
export function timeout<I, O, E, C extends object>(
source: Behavior<I, O, E, C>,
ms: number,
): Behavior<I, O, E | TimingError, C> {
return async (input, context) => runWithTimeout(source, input, context, ms);
}