Apply a default session timeout only if no timeout was set.
← Control Flow · Ref: Q1225
The :=? guarded assignment operator assigns a value ONLY if the target variable is currently unset. If the variable already has a value, the assignment is skipped.
timeout <- Duration() defaultTimeout <- PT30M timeout :=? defaultTimeout //timeout is now 30 minutes because it was unset
This is an ASSIGNMENT operator — it sets a variable.
See Q1038 for :=? with config fallback chains.
Example
defines module qa.flow.guardassign.duration defines function loadTimeoutFromConfig() <- rtn <- Duration() //Simulates: no timeout in configuration loadTimeoutFromProfile() <- rtn <- PT15M defines program GuardAssignDurationDemo() stdout <- Stdout() // === TIMEOUT IS UNSET — :=? assigns the default === timeout <- Duration() defaultTimeout <- PT30M timeout :=? defaultTimeout stdout.println(`Session timeout: ${timeout}`) // === TIMEOUT IS ALREADY CONFIGURED — :=? is skipped === customTimeout <- PT1H customTimeout :=? defaultTimeout stdout.println(`Custom timeout preserved: ${customTimeout}`) // === FALLBACK CHAIN — first set value wins === sessionTimeout <- Duration() sessionTimeout :=? loadTimeoutFromConfig() sessionTimeout :=? loadTimeoutFromProfile() sessionTimeout :=? defaultTimeout stdout.println(`Effective timeout: ${sessionTimeout}`)
Common mistakes
E01073 — EK9 has no null. Use :=? to conditionally assign — it only sets the value when the variable is currently unset. See ek9 -h E01072 for details.
Incorrect:
if timeout == null timeout := defaultTimeout
Correct:
timeout :=? defaultTimeout
Other ways to ask this
- How do I conditionally assign a Duration only when the variable is unset?
- A web application has an optional session timeout — apply a default if not configured.
- In Java I'd check if timeout == null before assigning a Duration default. What does EK9 use?
- Migrating from C# where I use '??' for nullable TimeSpan — what is the EK9 pattern?
Coming from another language?
Java: if (timeout == null) timeout = Duration.ofMinutes(30). Python: timeout = timeout or timedelta(minutes=30). C#: timeout = timeout ?? TimeSpan.FromMinutes(30). Go: if timeout == 0 { timeout = 30 * time.Minute }. EK9: timeout :=? defaultTimeout — one operator, correct tri-state semantics.
Keywords: session, web, guarded, duration, timeout, default, assignment, :=?