Skip to content

PersistentAI API Documentation / @persistent-ai/fireflow-types / withTimeout

Function: withTimeout()

withTimeout<T>(promise, timeoutMs, timeoutMessage): Promise<T>

Defined in: packages/fireflow-types/src/utils/timeout.ts:18

Utility function to add a timeout to a promise. If the promise does not resolve within the specified time, it will be rejected with a timeout error.

Type Parameters

T

T

Parameters

promise

Promise<T>

The promise to wrap with a timeout.

timeoutMs

number

The timeout duration in milliseconds. If -1 or 0 is passed, the timeout is disabled and the original promise is returned.

timeoutMessage

string

The error message for the timeout rejection.

Returns

Promise<T>

A new promise that resolves or rejects based on the original promise and the timeout.

Licensed under BUSL-1.1