aws/waiter

Polling helper for Smithy @waitable operations.

The codegen-emitted wait_until_<name> functions are thin wrappers over wait. Each wrapper:

  1. Invokes the underlying typed operation in a step closure.
  2. Matches the result against the waiter’s acceptors (a list of state + matcher rules lifted from the Smithy trait). Returns Settled when an acceptor with state: success matches, FailedNow(err) when state: failure matches, Continue otherwise.
  3. Calls wait(step, max_attempts, min_delay, max_delay) to drive the loop with exponential backoff between attempts.

Backoff doubles the previous delay (starting at min_delay_ms) up to max_delay_ms — Smithy’s standard waiter cadence. The helper sleeps between attempts via process.sleep; tests pass zero delays so they don’t block.

step carries the 1-indexed attempt number. The codegen generally ignores it but specialised callers can use it for dynamic adjustments (e.g. emit a log line per attempt).

Types

What a single waiter step produced. The codegen-emitted wait_until_<name> wrapper turns the typed operation’s Result(Output, Error) plus the configured acceptors into one of these three states.

pub type Step(error) {
  Settled
  Continue
  FailedNow(error)
}

Constructors

  • Settled

    At least one state: success acceptor matched — the wait returns Ok(Nil) immediately.

  • Continue

    No acceptor matched yet — sleep for the current backoff and re-invoke step (unless we’ve hit max_attempts).

  • FailedNow(error)

    A state: failure acceptor matched — the wait returns Error(Failed(_)) immediately, no further attempts.

What can go wrong driving a waiter to completion.

pub type WaiterError(error) {
  Failed(error: error)
  MaxAttemptsExceeded(attempts: Int)
}

Constructors

  • Failed(error: error)

    A state: failure acceptor matched on attempt attempts.

  • MaxAttemptsExceeded(attempts: Int)

    Reached the configured max_attempts without ever settling or failing. attempts is the actual number of attempts made.

Values

pub fn wait(
  step step: fn(Int) -> Step(error),
  max_attempts max_attempts: Int,
  min_delay_ms min_delay_ms: Int,
  max_delay_ms max_delay_ms: Int,
) -> Result(Nil, WaiterError(error))

Drive a waiter step closure to completion, sleeping between attempts with exponential backoff capped at max_delay_ms. Returns Ok(Nil) on settle, Error(Failed(_)) on a state: failure acceptor match, Error(MaxAttemptsExceeded(_)) when the attempt budget is exhausted. max_attempts == 0 is a defensive guard that returns immediately without invoking step.

Search Document