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
impl Delay
Sourcepub fn timeout(timeout: Duration) -> Self
pub fn timeout(timeout: Duration) -> Self
A Delay that doesn’t wait, but times out after a while.
Sourcepub fn count_timeout(count: u64) -> Self
pub fn count_timeout(count: u64) -> Self
A Delay that times out after waiting a certain number of times.
Sourcepub fn throttle(throttle: Duration) -> Self
pub fn throttle(throttle: Duration) -> Self
A delay that waits every wait() call for a certain time.
Sourcepub fn exponential_backoff_capped(
initial: Duration,
multiplier: f32,
cap: Duration,
) -> Self
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).
Sourcepub fn exponential_backoff(initial: Duration, multiplier: f32) -> Self
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.
Sourcepub fn side_effect<F>(function: F) -> Self
pub fn side_effect<F>(function: F) -> Self
Call a function every tick, expecting some kind of side effect (e.g. a progress bar).