RetryPolicy
#struct RetryPolicyA retry policy.
| Name | Type | Description |
|---|---|---|
max_attempts | int = 3 | The greatest number of attempts; three by default. |
base_delay_ms | int = 100 | The delay after the first failed attempt, in milliseconds; 100 by default. |
max_delay_ms | int = 5000 | The ceiling on the delay, in milliseconds; 5000 by default. |
import error
func main:
mut policy := error.NewRetryPolicy(4, 100, 1000)
println policy.max_attempts, policy.base_delay_ms, policy.max_delay_ms
e := Error.New(ErrorKind.Timeout, "the server did not answer")
println error.KindName(e.kind), error.IsRetryable(e)
mut attempt := 1
until error.ShouldRetry(policy, e, attempt):
println "attempt", attempt, "after", error.DelayForAttempt(policy, attempt), "milliseconds"
attempt++
end
println error.ShouldRetry(policy, Error.New(ErrorKind.InvalidArgument, "bad input"), 1)
end4 100 1000 timed out true attempt 1 after 100 milliseconds attempt 2 after 200 milliseconds attempt 3 after 400 milliseconds false