API reference@evolu/commonSchedule › whenInput

function whenInput<Input, Output>(
  predicate: Predicate<Input>,
  altSchedule: Schedule<Output, Input>,
): (schedule: Schedule<Output, Input>) => Schedule<Output, Input>;

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

Selects between two schedules based on input.

If Predicate returns true, uses altSchedule; otherwise uses the base schedule. Useful for implementing error-aware backoff where certain errors (e.g., throttling) use different delays.

Example

interface MyError extends Typed<"Throttled" | "NetworkError"> {}

const awsWithThrottling = whenInput<MyError, Millis>(
  (error) => error.type === "Throttled",
  exponential("1s"), // throttled: 1s base
)(exponential("100ms")); // normal: 100ms base