pub enum Delay {
None,
Fixed(Duration),
Random {
min: Duration,
max: Duration,
},
Exponential {
initial: Duration,
max: Duration,
multiplier: f64,
},
}Expand description
Base delay strategy before jitter is applied.
Delay strategies are value types that can be reused across executors. Random
and exponential strategies are validated separately by Delay::validate,
which is called when building crate::RetryOptions.
Variants§
None
Retry immediately.
Fixed(Duration)
Wait for a constant delay after every failed attempt.
Random
Pick a delay uniformly from the inclusive range.
Exponential
Exponential backoff capped by max.
Implementations§
Source§impl Delay
impl Delay
Sourcepub fn none() -> Delay
pub fn none() -> Delay
Creates a no-delay strategy.
§Parameters
This function has no parameters.
§Returns
A Delay::None strategy.
§Errors
This function does not return errors.
Sourcepub fn fixed(delay: Duration) -> Delay
pub fn fixed(delay: Duration) -> Delay
Creates a fixed-delay strategy.
§Parameters
delay: Duration slept after each failed attempt.
§Returns
A Delay::Fixed strategy.
§Errors
This constructor does not validate delay; use Delay::validate to
reject a zero duration.
Sourcepub fn random(min: Duration, max: Duration) -> Delay
pub fn random(min: Duration, max: Duration) -> Delay
Creates a random-delay strategy.
§Parameters
min: Inclusive lower bound for generated delays.max: Inclusive upper bound for generated delays.
§Returns
A Delay::Random strategy.
§Errors
This constructor does not validate the range; use Delay::validate to
reject a zero minimum or a minimum greater than the maximum.
Sourcepub fn exponential(initial: Duration, max: Duration, multiplier: f64) -> Delay
pub fn exponential(initial: Duration, max: Duration, multiplier: f64) -> Delay
Creates an exponential-backoff strategy.
§Parameters
initial: Delay used for the first retry.max: Upper bound applied to every calculated delay.multiplier: Factor applied for each subsequent failed attempt.
§Returns
A Delay::Exponential strategy.
§Errors
This constructor does not validate the parameters; use
Delay::validate to reject a zero initial delay, max < initial, or
a multiplier that is non-finite or less than or equal to 1.0.
Sourcepub fn base_delay(&self, attempt: u32) -> Duration
pub fn base_delay(&self, attempt: u32) -> Duration
Calculates the base delay for an attempt number starting at 1.
Attempt 1 means the first failed attempt, so exponential backoff
returns initial for attempts 0 and 1. Random delays use a fresh
random value for every call.
§Parameters
attempt: Failed attempt number. Values0and1are treated as the first exponential-backoff step.
§Returns
The base delay before jitter is applied.
§Errors
This function does not return errors. Invalid strategies should be
rejected with Delay::validate before they are used in an executor.
Sourcepub fn validate(&self) -> Result<(), String>
pub fn validate(&self) -> Result<(), String>
Validates strategy parameters.
Returns a human-readable message describing the invalid field when the strategy cannot be used safely by an executor.
§Returns
Ok(()) when all parameters are usable; otherwise an error message that
can be wrapped by crate::RetryConfigError.
§Parameters
This method has no parameters.
§Errors
Returns an error when a fixed delay is zero, a random range is invalid, or exponential backoff parameters are zero, inverted, non-finite, or too small.