aws/waiter
Polling helper for Smithy @waitable operations.
The codegen-emitted wait_until_<name> functions are thin
wrappers over wait. Each wrapper:
- Invokes the underlying typed operation in a
stepclosure. - Matches the result against the waiter’s acceptors (a list
of
state+matcherrules lifted from the Smithy trait). ReturnsSettledwhen an acceptor withstate: successmatches,FailedNow(err)whenstate: failurematches,Continueotherwise. - 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
-
SettledAt least one
state: successacceptor matched — the wait returnsOk(Nil)immediately. -
ContinueNo acceptor matched yet — sleep for the current backoff and re-invoke
step(unless we’ve hitmax_attempts). -
FailedNow(error)A
state: failureacceptor matched — the wait returnsError(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: failureacceptor matched on attemptattempts. -
MaxAttemptsExceeded(attempts: Int)Reached the configured
max_attemptswithout ever settling or failing.attemptsis 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.