31 — Schedules
A Schedule is a reusable policy describing repetition or retry. Begin with bounded policies such as Schedule.recurs, add delay policies such as Schedule.exponential, and use Schedule.while when continuation depends on the current input metadata.
Policies belong beside the operational boundary they protect. Always bound retries, distinguish expected retryable errors, and test time-dependent behaviour with TestClock.
The full test suite
The index.test.ts for this lesson, verbatim from steps/31-schedules/.
import { describe, expect, it } from "vite-plus/test"import { Effect, Ref, Schedule } from "effect"
describe("Schedule", () => { it("retries according to an explicit policy", async () => { const program = Effect.gen(function*() { const attempts = yield* Ref.make(0) const operation = Ref.updateAndGet(attempts, (n) => n + 1).pipe( Effect.flatMap((n) => n < 3 ? Effect.fail("retry") : Effect.succeed(n)), Effect.retry(Schedule.recurs(2)), ) return yield* operation }) expect(await Effect.runPromise(program)).toBe(3) })})