Skip to main content

Module Call Options

warning

Options are evaluated at compile time. Runtime values cannot be used as option values. For example, retry: myVariable is invalid; use literals like retry: 3.

Module call options allow you to control how module calls execute with built-in resilience, caching, and scheduling features. Options are specified using the with clause after a module call.

Syntax

result = ModuleName(arg1, arg2) with option1: value1, option2: value2

Options are comma-separated key-value pairs. Multiple options can be combined to create sophisticated execution policies.

Quick Reference

OptionTypeDescription
retryIntegerMaximum retry attempts on failure
timeoutDurationMaximum execution time per attempt
delayDurationBase delay between retries
backoffStrategyHow delay increases between retries
fallbackExpressionValue to use if all retries fail
cacheDurationTTL for caching results
cache_backendStringNamed cache backend to use
throttleRateMaximum call rate limit
concurrencyIntegerMaximum parallel executions
on_errorStrategyError handling behavior
lazyBooleanDefer execution until needed
priorityLevelScheduling priority hint

Option Categories

Resilience Options

Options for handling failures and ensuring reliable execution:

  • retry - Automatic retry on failure
  • timeout - Time limit per execution attempt
  • delay - Wait time between retries
  • backoff - Delay increase strategy
  • fallback - Default value on failure

Caching Options

Options for result caching and storage:

Rate Control Options

Options for managing execution rate and resources:

Advanced Options

Options for fine-tuned execution control:

Value Types

Duration

Time values with unit suffix:

UnitSuffixExample
Millisecondsms500ms
Secondss30s
Minutesmin5min
Hoursh1h
Daysd1d

Rate

Request rate in format count/duration:

throttle: 100/1min    # 100 calls per minute
throttle: 10/1s # 10 calls per second
throttle: 1000/1h # 1000 calls per hour

Strategies

Backoff strategies:

  • fixed - Constant delay between retries
  • linear - Delay increases linearly (N × base delay)
  • exponential - Delay doubles each retry (capped at 30s)

Error strategies:

  • propagate - Re-throw the error (default)
  • skip - Return zero value for the type
  • log - Log error and return zero value
  • wrap - Wrap error in result type

Priority levels:

  • critical - Highest priority
  • high - Above normal
  • normal - Default priority
  • low - Below normal
  • background - Lowest priority

Examples

tip

Combine multiple options to build robust pipelines. A common pattern is retry: 3, delay: 1s, backoff: exponential, timeout: 30s, fallback: defaultValue for external API calls.

Basic Retry with Timeout

in url: String

response = HttpGet(url) with retry: 3, timeout: 10s
out response

If HttpGet fails, it will retry up to 3 times. Each attempt has a 10-second timeout.

Retry with Exponential Backoff

in apiEndpoint: String

result = FetchData(apiEndpoint) with
retry: 5,
delay: 1s,
backoff: exponential,
timeout: 30s

out result

Retries with delays of 1s, 2s, 4s, 8s, 16s (exponential backoff, capped at 30s).

Caching Expensive Operations

in userId: String

profile = LoadUserProfile(userId) with cache: 15min

out profile

Results are cached for 15 minutes. Subsequent calls with the same userId return the cached value.

Rate-Limited API Calls

in requests: List[Request]

results = requests.map(r => ProcessRequest(r) with throttle: 100/1min)

out results

Limits processing to 100 requests per minute to respect API rate limits.

Fallback Values

in stockSymbol: String

price = GetStockPrice(stockSymbol) with
retry: 2,
timeout: 5s,
fallback: 0.0

out price

If GetStockPrice fails after retries, returns 0.0 instead of raising an error.

Complete Resilient Pipeline

in inputData: Record

# Step 1: Validate with quick timeout
validated = Validate(inputData) with timeout: 1s

# Step 2: Transform with retry and caching
transformed = Transform(validated) with
retry: 3,
delay: 500ms,
backoff: exponential,
cache: 10min

# Step 3: Store with fallback
stored = Store(transformed) with
retry: 5,
timeout: 30s,
fallback: { success: false, reason: "storage unavailable" }

out stored

Option Interactions

Retry + Timeout

note

Timeout applies per attempt, not total. With retry: 3, timeout: 10s, total maximum time is 40s (4 attempts x 10s each). Plan your timeout values accordingly to avoid unexpectedly long operations.

Timeout applies per attempt, not total. With retry: 3, timeout: 10s, total maximum time is 40s (4 attempts × 10s each).

Retry + Delay + Backoff

The delay option sets the base delay. The backoff strategy determines how the delay changes:

AttemptFixedLinear (1s base)Exponential (1s base)
1 → 21s1s1s
2 → 31s2s2s
3 → 41s3s4s
4 → 51s4s8s
5 → 61s5s16s

Cache + Retry

Caching occurs after successful execution. Failed results are not cached. Retries happen before the result is cached.

Fallback + On_Error

If both are specified, fallback takes precedence for providing a default value. Use on_error for handling errors differently (logging, wrapping, etc.).

Warnings and Diagnostics

The compiler provides warnings for potentially incorrect option combinations:

WarningDescription
delay without retryDelay has no effect without retry
backoff without delayBackoff requires a base delay
backoff without retryBackoff has no effect without retry
cache_backend without cacheBackend requires cache option
High retry countMore than 10 retries may indicate a problem

Errors are raised for invalid values:

ErrorDescription
Negative retryRetry count must be non-negative
Zero concurrencyConcurrency must be positive
Unknown optionUnrecognized option name
Duplicate optionSame option specified twice

IDE Support

Autocomplete

After with, the IDE suggests available option names. After the colon:

  • Duration options show unit completions (ms, s, min, h, d)
  • Strategy options show valid values (exponential, skip, etc.)
  • Priority shows level names (critical, high, etc.)

Hover Information

Hover over any option name to see:

  • Description of the option
  • Type signature
  • Usage examples
  • Related options

Diagnostics

Real-time warnings appear for:

  • Ineffective option combinations (delay without retry)
  • High retry counts (> 10)
  • Invalid values

See Also