Skip to main content

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.

delay requires retry

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

  1. First attempt executes immediately
  2. If the attempt fails and retries remain:
    • Wait for the computed delay (based on delay and backoff)
    • Execute the next attempt
  3. Continue until success or retries exhausted

Delay Calculation with Backoff

StrategyFormulaExample (base: 1s)
fixedconstant1s, 1s, 1s, 1s
linearN × delay1s, 2s, 3s, 4s
exponential2^(N-1) × delay1s, 2s, 4s, 8s

Note: Exponential backoff is capped at 30 seconds maximum.

Duration Units

UnitSuffixExample
Millisecondsms100ms, 500ms
Secondss1s, 5s
Minutesmin1min
Hoursh1h
Daysd1d
  • retry - Required for delay to have effect
  • backoff - How delay changes over retries
  • timeout - Time limit per attempt

Diagnostics

WarningCause
delay without retryDelay 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