06·02Retry & Timeout

`Effect.retry(schedule)` repeats according to an explicit, bounded policy. `Effect.timeout(duration)` adds a typed `TimeoutError` and interrupts the underlying fiber when the deadline wins. Use `Effect.timeoutOrElse` when the domain needs a custom timeout fail

32 — Retry and deadlines

Effect.retry(schedule) repeats according to an explicit, bounded policy. Effect.timeout(duration) adds a typed TimeoutError and interrupts the underlying fiber when the deadline wins. Use Effect.timeoutOrElse when the domain needs a custom timeout failure.

Retry only transient operations, keep idempotency in view, and put deadlines around the complete operation rather than an arbitrary internal fragment.


The full test suite

The index.test.ts for this lesson, verbatim from steps/32-retry-and-timeout/.

index.test.ts
import { describe, expect, it } from "vite-plus/test"
import { Effect, Exit, Schedule } from "effect"
describe("retry and timeout", () => {
it("keeps retry and deadline policies visible", async () => {
const exit = await Effect.runPromiseExit(
Effect.fail("unavailable").pipe(Effect.retry(Schedule.recurs(2)), Effect.timeout("50 millis")),
)
expect(Exit.isFailure(exit)).toBe(true)
})
})
← PreviousSchedulesNext →Source Patterns