API reference › @evolu/common › Schedule › during
function during(
duration: Duration,
): Schedule<
number &
Brand<"NonNaN"> &
Brand<"Finite"> &
Brand<"Int"> &
Brand<"NonNegative"> &
Brand<"LessThan281474976710655"> &
Brand<"Millis">
>;
Defined in: packages/common/src/Schedule.ts:656
A schedule that runs for a specified duration then stops.
Outputs the elapsed time. Useful for time-boxed operations or combining with other schedules to create time-limited variants.
Time-boxing a schedule
import {
assertErr,
assertOk,
done,
during,
exponential,
intersectSchedules,
testCreateDeps,
} from "@evolu/common";
// Run for at most 30 seconds.
const timeLimited = during("30s");
const deps = testCreateDeps();
const step = timeLimited(deps);
assertOk(step(undefined), [0, 0]);
deps.time.advance("30.1s");
assertErr(step(undefined), done());
// Combine elapsed time with backoff for a time-boxed retry.
const timedRetry = intersectSchedules(exponential("100ms"), during("10s"));
assertOk(timedRetry(testCreateDeps())(undefined), [[100, 0], 100]);