Skip to main content

Function: raceWithTimeout()

function raceWithTimeout<T>(
operation: Promise<T>,
options: RaceWithTimeoutOptions
): Promise<T>;

Defined in: shared/utils/abortUtils.ts:796

Races an operation promise against a timeout (and optional AbortSignal).

Type Parametersโ€‹

Tโ€‹

T

Resolved value of the underlying operation.

Parametersโ€‹

operationโ€‹

Promise<T>

Promise to race.

optionsโ€‹

RaceWithTimeoutOptions

Timeout and optional abort configuration.

Returnsโ€‹

Promise<T>

The first settled result between the operation, timeout, and abort.

Remarksโ€‹

This helper is intended for APIs that do not support abort natively. Timeout rejections are regular Error instances (not abort errors) so callers can distinguish "timed out" from user cancellation when desired.

When unrefTimer is enabled and the runtime exposes unref() on timer handles (Node.js/Electron), the timeout will not keep the event loop alive.

Throwsโ€‹

Error when the timeout elapses.

Throwsโ€‹

Error when the abort signal triggers (via raceWithAbort).