API reference › @evolu/common › Schedule › maxElapsed
function maxElapsed(
duration: Duration,
): <Output, Input>(
schedule: Schedule<Output, Input>,
) => Schedule<Output, Input>;
Defined in: packages/common/src/Schedule.ts:820
Limits schedule execution to a maximum elapsed time since its first step.
After duration has elapsed since the first step, returns Err(Done<void>).
Limiting elapsed time
import {
assertErr,
assertOk,
done,
exponential,
maxElapsed,
testCreateDeps,
} from "@evolu/common";
// Retry for at most 30 seconds.
const deps = testCreateDeps();
const step = maxElapsed("30s")(exponential("1s"))(deps);
assertOk(step(undefined), [1000, 1000]);
deps.time.advance("30s");
assertErr(step(undefined), done());