Pick the shorter of two timeout durations for a retry policy.
← Operators and Expressions · Ref: Q1210
The <? coalescing minimum operator returns the shorter of two Duration values, handling unset gracefully.
shorterTimeout() as pure -> left as Duration, right as Duration <- rtn as Duration: left <? right
If both durations are set, <? returns the shorter one. If one is unset (unconfigured), it returns the configured timeout. If both are unset, the result is unset.
This is a COMPARISON operator — it picks the smaller value. Do not confuse it with :=? (guarded assignment), which assigns only if the target is unset. See Q1226 for a side-by-side contrast.
See Q1092 for min/max coalescing overview. See Q1188 for Duration operations.
Example
defines module qa.operators.coalescemin.duration defines function shorterTimeout() as pure -> left as Duration right as Duration <- rtn as Duration: left <? right defines program CoalesceMinDurationDemo() stdout <- Stdout() // === BOTH CONFIGURED — returns the shorter === primaryTimeout <- PT30S fallbackTimeout <- PT15S chosenTimeout <- shorterTimeout(primaryTimeout, fallbackTimeout) stdout.println(`Chosen timeout: ${chosenTimeout}`) // === ONE UNCONFIGURED — returns the configured one === configuredTimeout <- PT45S missingTimeout <- Duration() effectiveTimeout <- shorterTimeout(configuredTimeout, missingTimeout) stdout.println(`Effective timeout: ${effectiveTimeout}`) // === NEITHER CONFIGURED — result is unset === missingFirst <- Duration() missingSecond <- Duration() noTimeout <- shorterTimeout(missingFirst, missingSecond) if noTimeout? stdout.println(`Timeout: ${noTimeout}`) else stdout.println("No timeout configured")
Other ways to ask this
- How do I select the minimum Duration when one timeout might be unconfigured?
- A retry policy has primary and fallback timeouts — pick the shorter one safely.
- In Java I'd need null checks before comparing Duration objects. What does EK9 use?
- Migrating from Python where I use min() with None filtering for timedeltas — what is the EK9 way?
Coming from another language?
Java: a == null ? b : b == null ? a : a.compareTo(b) <= 0 ? a : b. Python: min(d for d in [a, b] if d is not None). Go: if a == 0 { return b } else if b == 0 { return a } else { return min(a, b) }. EK9: left <? right — one operator handles all cases.
Keywords: coalescing, duration, <?, policy, timeout, minimum, shorter, retry