API reference@evolu/commonTask › timeout

function timeout<T, E, D>(
  task: Task<T, E, D>,
  duration: PositiveDuration,
): Task<T, TimeoutError | E, D>;

Defined in: packages/common/src/Task.ts:3684

Limits how long a Task may run.

Returns the Task Result when it settles within the duration. Otherwise, the Task is aborted and TimeoutError is returned. A Task that doesn't observe abort delays the TimeoutError until it settles; when that wait is unacceptable, wrap the Task with daemon: timeout(daemon(task), duration).

Example

import {
  createRun,
  timeout,
  timeoutError,
  waitForAbort,
  type Result,
  type TimeoutError,
} from "@evolu/common";

await using run = createRun();

const result = await run(timeout(waitForAbort, "1ms"));
expectTypeOf(result).toEqualTypeOf<Result<never, TimeoutError>>();
expectErr(result, timeoutError);