Struct Delay

Source
pub struct Delay { /* private fields */ }
Expand description

A Delay struct that encapsulates a Waiter.

To use this class, first create an instance of it by either calling a method on it (like Delay::timeout) or create a builder and add multiple Waiters. Then when you’re ready to start a process that needs to wait, use the [start()] function. Every wait period, call the [wait()] function on it (it may block the thread).

Implementations§

Source§

impl Delay

Source

pub fn instant() -> Self

A Delay that never waits. This can hog resources, so careful.

Source

pub fn timeout(timeout: Duration) -> Self

A Delay that doesn’t wait, but times out after a while.

Source

pub fn count_timeout(count: u64) -> Self

A Delay that times out after waiting a certain number of times.

Source

pub fn throttle(throttle: Duration) -> Self

A delay that waits every wait() call for a certain time.

Source

pub fn exponential_backoff_capped( initial: Duration, multiplier: f32, cap: Duration, ) -> Self

A delay that recalculate a wait time every wait() calls and exponentially waits. The calculation is new_wait_time = max(current_wait_time * multiplier, cap).

Source

pub fn exponential_backoff(initial: Duration, multiplier: f32) -> Self

A delay that recalculate a wait time every wait() calls and exponentially waits. The calculation is new_wait_time = current_wait_time * multiplier. There is no limit for this backoff.

Source

pub fn side_effect<F>(function: F) -> Self
where F: 'static + Sync + Send + Clone + Fn() -> Result<(), WaiterError>,

Call a function every tick, expecting some kind of side effect (e.g. a progress bar).

Source

pub fn builder() -> DelayBuilder

Trait Implementations§

Source§

impl Clone for Delay

Source§

fn clone(&self) -> Delay

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Waiter for Delay

Source§

fn restart(&mut self) -> Result<(), WaiterError>

Restart the wait timer. Call after starting the waiter otherwise returns an error.
Source§

fn start(&mut self)

Called when we start the waiting cycle.
Source§

fn wait(&self) -> Result<(), WaiterError>

Called at each cycle of the waiting cycle. Call after starting the waiter otherwise returns an error.

Auto Trait Implementations§

§

impl Freeze for Delay

§

impl !RefUnwindSafe for Delay

§

impl Send for Delay

§

impl !Sync for Delay

§

impl Unpin for Delay

§

impl !UnwindSafe for Delay

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<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> 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<T> WaiterClone for T
where T: 'static + Waiter + Clone,

Source§

fn clone_box(&self) -> Box<dyn Waiter>