Skip to main content

Options

Struct Options 

Source
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 minutes

Implementations§

Source§

impl Options

Source

pub const DEFAULT: Options

Default ease-off options which should be suitable for most applications.

See source for current values.

Source

pub const fn new() -> Self

Returns Self::DEFAULT.

Source

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.

Source

pub const fn get_multiplier(&self) -> f32

Get the factor that the next delay will be multiplied by.

Source

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.

Source

pub const fn get_jitter(&self) -> f32

Get the maximum jitter factor.

See Self::jitter() for details.

Source

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.

Source

pub const fn get_initial_jitter(&self) -> f32

Get the jitter factor used for the first attempt.

See Self::initial_jitter() for details.

Source

pub const fn initial_delay(self, initial_delay: Duration) -> Self

Set the delay for the first backoff attempt.

Source

pub const fn get_initial_delay(&self) -> Duration

Get the delay for the first backoff attempt.

See Self::initial_delay() for details.

Source

pub const fn max_delay(self, max_delay: Duration) -> Self

Set the maximum delay to wait between backoff attempts.

Source

pub const fn get_max_delay(&self) -> Duration

Get the maximum delay to wait between backoff attempts.

See Self::max_delay() for details.

Source

pub const fn into_core(self) -> EaseOffCore

Convert this Options into an EaseOffCore.

Source§

impl Options

Methods to create an EaseOff.

Source

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.

Source

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:

Source

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:

Source

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:

Source

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:

Trait Implementations§

Source§

impl Clone for Options

Source§

fn clone(&self) -> Options

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Options

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Options

Source§

fn default() -> Self

Returns Self::DEFAULT.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V