API reference@evolu/commonSchedule › windowed

function windowed(interval: Duration): Schedule<number>;

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

Divides the timeline into fixed windows and sleeps until the next boundary.

Similar to fixed, but skips missed recurrences and always sleeps until the next window boundary. Outputs the repetition count.

Useful for aligning executions to regular intervals from the first step.

Aligning to time windows

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

const stepAfter = (elapsed: "3s" | "7s") => {
  const deps = testCreateDeps();
  const step = windowed("5s")(deps);
  step(undefined);
  deps.time.advance(elapsed);
  return step(undefined);
};

// At 3s the next boundary is 2s away; at 7s it is 3s away.
assertOk(stepAfter("3s"), [1, 2000]);
assertOk(stepAfter("7s"), [1, 3000]);