API reference@evolu/commonSchedule › maxDelay

function maxDelay(
  max: Duration,
): <Output, Input>(
  schedule: Schedule<Output, Input>,
) => Schedule<Output, Input>;

Defined in: packages/common/src/Schedule.ts:867

Caps the delay to a maximum value.

If the schedule returns a delay greater than max, returns max instead.

Capping delays

import { assertOk, exponential, maxDelay, testCreateDeps } from "@evolu/common";

// Exponential delays grow 1s, 2s, 4s, 8s, then stay capped at 10s.
const step = maxDelay("10s")(exponential("1s"))(testCreateDeps());
step(undefined);
step(undefined);
step(undefined);
step(undefined);
assertOk(step(undefined), [16000, 10000]);