Skip to content

timeout

timeout<E>(duration, onTimeout): <A>(task) => Task<Result<E, A>>

Defined in: Core/Task.ts:421

Converts a Task<A> into a Task<Result<E, A>>, resolving to Err if the Task does not complete within the given duration. The inner Task receives an AbortSignal that fires when the deadline passes, so asynchronous operations that accept a signal are cancelled rather than left dangling.

E

Duration

() => E

<A>(task) => Task<Result<E, A>>

pipe(
  heavyComputation,
  Task.timeout(Duration.seconds(5), () => "timed out"),
  TaskResult.chain(processResult)
);