delay
Set the base delay between retry attempts.
Syntax
result = Module(args) with retry: N, delay: <duration>
Type: Duration (ms, s, min, h, d)
Description
The delay option specifies the wait time between retry attempts. It is typically used with retry and optionally with backoff to control how the delay changes over time.
Without backoff or with backoff: fixed, the delay remains constant. With other backoff strategies, the delay value serves as the base delay that gets modified.
Using delay without retry has no effect and generates a compiler warning. The delay only applies between retry attempts, not before the initial execution.
Examples
Fixed Delay
result = FlakyService(input) with retry: 3, delay: 1s
Wait 1 second between each retry attempt.
Delay with Backoff
response = ApiCall(request) with
retry: 5,
delay: 500ms,
backoff: exponential
Delays: 500ms, 1s, 2s, 4s, 8s (exponential increase).
Short Delay for Fast Retries
cached = GetFromCache(key) with retry: 2, delay: 50ms
Quick retries for transient cache misses.
Delay Without Retry
# Warning: delay has no effect without retry
result = Operation(data) with delay: 1s
This generates a compiler warning since delay only applies between retries.
Behavior
- First attempt executes immediately
- If the attempt fails and retries remain:
- Wait for the computed delay (based on
delayandbackoff) - Execute the next attempt
- Wait for the computed delay (based on
- Continue until success or retries exhausted
Delay Calculation with Backoff
| Strategy | Formula | Example (base: 1s) |
|---|---|---|
fixed | constant | 1s, 1s, 1s, 1s |
linear | N × delay | 1s, 2s, 3s, 4s |
exponential | 2^(N-1) × delay | 1s, 2s, 4s, 8s |
Note: Exponential backoff is capped at 30 seconds maximum.
Duration Units
| Unit | Suffix | Example |
|---|---|---|
| Milliseconds | ms | 100ms, 500ms |
| Seconds | s | 1s, 5s |
| Minutes | min | 1min |
| Hours | h | 1h |
| Days | d | 1d |
Related Options
- retry - Required for delay to have effect
- backoff - How delay changes over retries
- timeout - Time limit per attempt
Diagnostics
| Warning | Cause |
|---|---|
| delay without retry | Delay has no effect without retry option |
Best Practices
- Start with short delays (100ms-1s)
- Use exponential backoff for rate-limited services
- Consider service recovery time when setting delays
- Balance retry speed against server load