API reference@evolu/commonSchedule › spaced

function spaced(
  duration: Duration,
): Schedule<
  number &
    Brand<"NonNaN"> &
    Brand<"Finite"> &
    Brand<"Int"> &
    Brand<"NonNegative"> &
    Brand<"LessThan281474976710655"> &
    Brand<"Millis">
>;

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

Constant delay schedule.

Always waits the same duration after each execution completes. Never stops — combine with take or maxElapsed to limit.

Constant spacing

import { assertOk, spaced, take, testCreateDeps } from "@evolu/common";

// Poll every second, retry three times, or run a long-lived heartbeat.
const poll = spaced("1s");
const retry = take(3)(spaced("500ms"));
const heartbeat = spaced("30s");
const deps = testCreateDeps();

assertOk(poll(deps)(undefined), [1000, 1000]);
assertOk(retry(deps)(undefined), [500, 500]);
assertOk(heartbeat(deps)(undefined), [30000, 30000]);