API reference › @evolu/common › Schedule › Schedule
type Schedule<Output, Input> = (
deps: ScheduleDeps,
) => (input: Input) => NextResult<readonly [Output, Millis]>;
Defined in: packages/common/src/Schedule.ts:57
Composable scheduling strategies for retry, repeat, rate limiting, and more.
A Schedule uses the State pattern: calling schedule(deps) creates a step
function with internal state captured in closures. Each call to step(input)
advances that state and returns Ok([Output, Millis]) or Err(Done<void>)
to stop. Multiple calls to schedule(deps) create independent state
instances.
Example
import { exponential, jitter, maxDelay, retry, take } from "@evolu/common";
const fetchWithRetry = retry(
fetchData,
// A jittered, capped, limited exponential backoff.
jitter(1)(maxDelay("20s")(take(2)(exponential("100ms")))),
);
Or use a preset:
import { retryStrategyAws, retry } from "@evolu/common";
const fetchWithRetry = retry(fetchData, retryStrategyAws);