2 The Retry Reference
This document describes the complete API of the retry library. For a gentler introduction and use cases, see The Retry Guide.
2.1 Core Retry API
procedure
(retryer [ #:handle handle-proc #:should-retry? should-retry-proc]) → retryer?
handle-proc : (-> any/c exact-nonnegative-integer? void?) = void
should-retry-proc : (-> any/c exact-nonnegative-integer? boolean?) = (const #t)
procedure
(call/retry retryer proc) → any
retryer : retryer? proc : (-> any)
If a value v is thrown on the nth retry, (retryer-handle retryer v n) is called to handle the exception (or rethrow it if the retryer doesn’t handle this particular kind of exception). The value of n starts at zero. Then, (retryer-should-retry? retryer n) is called to determine whether to retry. If that returns true, proc is called again and this process repeats. Otherwise, the value v is rethrown and attempts to call proc are abandoned. Invocations of call/retry may never terminate, as some retryers never stop retrying. For a shorthand syntax, see with-retry.
syntax
(with-retry retryer-expr body ...)
retryer-expr : retryer?
procedure
(retryer-handle retryer raised num-previous-retries) → void? retryer : retryer? raised : any/c num-previous-retries : exact-nonnegative-integer?
procedure
(retryer-should-retry? retryer raised num-previous-retries) → boolean? retryer : retryer? raised : any/c num-previous-retries : exact-nonnegative-integer?
2.2 Built-In Retryers
value
always-retryer : retryer? = (retryer)
value
never-retryer : retryer? = (retryer #:should-retry? (const #f))
procedure
(limit-retryer limit) → retryer?
limit : exact-nonnegative-integer?
procedure
(print-exn-retryer to-string) → retryer?
to-string : (-> string? exact-nonnegative-integer? string?)
procedure
(sleep-retryer sleep-amount-proc) → retryer?
sleep-amount-proc : (-> exact-nonnegative-integer? time-period?)
procedure
(sleep-retryer/random max-sleep-amount-proc) → retryer?
max-sleep-amount-proc : (-> exact-nonnegative-integer? time-period?)
procedure
(sleep-const-retryer sleep-amount) → retryer?
sleep-amount : exact-nonnegative-integer?
procedure
(sleep-const-retryer/random max-sleep-amount) → retryer?
max-sleep-amount : time-period?
procedure
(sleep-exponential-retryer sleep-amount [ #:exponent-base base]) → retryer? sleep-amount : time-period? base : (>/c 0) = 2
procedure
(sleep-exponential-retryer/random max-sleep-amount [ #:exponent-base base]) → retryer? max-sleep-amount : exact-nonnegative-integer? base : (>/c 0) = 2
2.3 Higher-Order Retryers
procedure
(retryer-compose ret ...) → retryer?
ret : retryer?
procedure
(cycle-retryer ret cycle-length) → retryer?
ret : retryer? cycle-length : exact-positive-integer?