pub struct Options { /* private fields */ }Expand description
Configuration options for EaseOff and EaseOffCore.
Designed to be stored in a const or static:
use std::time::Duration;
const BACKOFF_OPTS: ease_off::Options = ease_off::Options::new()
.initial_jitter(0.25)
.initial_delay(Duration::from_secs(1))
.max_delay(Duration::from_secs(5 * 60)); // 5 minutesImplementations§
Source§impl Options
impl Options
Sourcepub const DEFAULT: Options
pub const DEFAULT: Options
Default ease-off options which should be suitable for most applications.
See source for current values.
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Returns Self::DEFAULT.
Sourcepub const fn multiplier(self, multiplier: f32) -> Self
pub const fn multiplier(self, multiplier: f32) -> Self
Set the factor to multiply the next delay by.
- If
> 1, backoff is exponential. - If
== 1, backoff is constant before jitter. - If
< 1, backoff is logarithmic(?). In any case, not recommended.
Any multiplication that results in an invalid value for Duration saturates
to Duration::MAX or max_delay, whichever is lower.
Sourcepub const fn get_multiplier(&self) -> f32
pub const fn get_multiplier(&self) -> f32
Get the factor that the next delay will be multiplied by.
Sourcepub const fn jitter(self, jitter: f32) -> Self
pub const fn jitter(self, jitter: f32) -> Self
Set the maximum jitter factor.
The next backoff delay will be multiplied by a random factor in the range (1 - jitter, 1].
This helps prevent a situation where attempts line up from multiple processes following the same backoff algorithm, which would constitute a thundering herd.
This value is clamped to the interval [0, 1] when calculating the next delay.
If jitter is <= 0 or NaN, no random jitter is applied (not recommended for most cases).
If jitter >= 1, the next delay can be anywhere between [0, next_delay],
which means the next attempt could happen immediately, without waiting.
Sourcepub const fn get_jitter(&self) -> f32
pub const fn get_jitter(&self) -> f32
Get the maximum jitter factor.
See Self::jitter() for details.
Sourcepub const fn initial_jitter(self, initial_jitter: f32) -> Self
pub const fn initial_jitter(self, initial_jitter: f32) -> Self
Set the jitter factor used to delay the first attempt.
The initial wait before the first attempt will be initial_delay
multiplied by a random factor in the range (1 - initial_jitter, 1].
This mitigates the thundering herd problem when multiple processes start up at the same time and all try to access the same resource.
This value is clamped to the interval [0, 1] when calculating the initial delay.
If initial_jitter is <= 0 or NaN, the first attempt occurs immediately.
The delay after the first failure will be calculated as normal;
multiplier is not applied until after the first retryable failure.
Sourcepub const fn get_initial_jitter(&self) -> f32
pub const fn get_initial_jitter(&self) -> f32
Get the jitter factor used for the first attempt.
See Self::initial_jitter() for details.
Sourcepub const fn initial_delay(self, initial_delay: Duration) -> Self
pub const fn initial_delay(self, initial_delay: Duration) -> Self
Set the delay for the first backoff attempt.
Sourcepub const fn get_initial_delay(&self) -> Duration
pub const fn get_initial_delay(&self) -> Duration
Get the delay for the first backoff attempt.
See Self::initial_delay() for details.
Sourcepub const fn max_delay(self, max_delay: Duration) -> Self
pub const fn max_delay(self, max_delay: Duration) -> Self
Set the maximum delay to wait between backoff attempts.
Sourcepub const fn get_max_delay(&self) -> Duration
pub const fn get_max_delay(&self) -> Duration
Get the maximum delay to wait between backoff attempts.
See Self::max_delay() for details.
Sourcepub const fn into_core(self) -> EaseOffCore
pub const fn into_core(self) -> EaseOffCore
Convert this Options into an EaseOffCore.
Source§impl Options
Methods to create an EaseOff.
impl Options
Methods to create an EaseOff.
Sourcepub fn start_unlimited<E>(&self) -> EaseOff<E>
pub fn start_unlimited<E>(&self) -> EaseOff<E>
Begin backing off with indefinite retries.
The operation will be retried until it succeeds, or a non-retryable error occurs.
Sourcepub fn start_timeout<E>(&self, timeout: Duration) -> EaseOff<E>
pub fn start_timeout<E>(&self, timeout: Duration) -> EaseOff<E>
Begin backing off, limited by the given timeout.
Always makes one attempt, even if the timeout is zero or has elapsed by the time the first attempt is made.
See also:
Self::start_timeout_opt()for a conditional timeout.Self::start_deadline()to specify anInstantas a deadline.
Sourcepub fn start_timeout_opt<E>(&self, timeout: Option<Duration>) -> EaseOff<E>
pub fn start_timeout_opt<E>(&self, timeout: Option<Duration>) -> EaseOff<E>
Begin backing off, limited by the given optional timeout.
If timeout is None, this is equivalent to Self::start_unlimited().
Always makes one attempt, even if the timeout is zero or has elapsed by the time the first attempt is made.
See also:
Self::start_timeout()for a non-conditional timeout.Self::start_deadline_opt()to specify an optionalInstantas a deadline.
Sourcepub fn start_deadline<E>(&self, deadline: Instant) -> EaseOff<E>
pub fn start_deadline<E>(&self, deadline: Instant) -> EaseOff<E>
Begin backing off, halting attempts at the given deadline.
Always makes one attempt, even if the deadline is <= Instant::now() or has elapsed
by the time the first attempt is made.
See also:
Self::start_deadline_opt()for a conditional deadline.Self::start_timeout()to specify aDurationas a timeout.
Sourcepub fn start_deadline_opt<E>(&self, deadline: Option<Instant>) -> EaseOff<E>
pub fn start_deadline_opt<E>(&self, deadline: Option<Instant>) -> EaseOff<E>
Begin backing off, halting attempts at the given deadline.
If deadline is None, this is equivalent to Self::start_unlimited().
Always makes one attempt, even if the deadline is <= Instant::now() or has elapsed
by the time the first attempt is made.
See also:
Self::start_deadline()for a non-conditional deadline.Self::start_timeout_opt()to specify an optionalDurationas a timeout.