pub struct EaseOff<E> { /* private fields */ }Expand description
Exponential backoff controller.
The constructors of this type use Options::DEFAULT.
Implementations§
Source§impl<E> EaseOff<E>
Backoff support for async/await.
impl<E> EaseOff<E>
Backoff support for async/await.
§Note: Behavior at Deadline
Unless otherwise stated, async operations are not cancelled at the deadline once they are in-progress.
More specifically, if the deadline elapses after an async operation has begun, i.e.
the future returned by these methods is .awaited or polled,
it will be allowed to run to completion.
To cancel an in-progress operation when the deadline elapses,
use TryAsync::enforce_deadline_with().
Sourcepub fn try_async<T, Fut>(
&mut self,
op: Fut,
) -> TryAsync<'_, E, impl FnOnce() -> Fut>
Available on crate features async-io-2 or tokio only.
pub fn try_async<T, Fut>( &mut self, op: Fut, ) -> TryAsync<'_, E, impl FnOnce() -> Fut>
async-io-2 or tokio only.Attempt an async operation.
The operation is immediately cancelled without being polled if the deadline has already elapsed. Otherwise, it is run to completion.
See the note on this impl block for details.
Sourcepub fn try_async_with<T, F, Fut>(&mut self, op: F) -> TryAsync<'_, E, F>
Available on crate features async-io-2 or tokio only.
pub fn try_async_with<T, F, Fut>(&mut self, op: F) -> TryAsync<'_, E, F>
async-io-2 or tokio only.Attempt the async operation returned by the given closure.
This allows for some lazy computation that is not executed if the deadline has already elapsed.
The closure is not called if the deadline has elapsed by the time the returned Future
is polled. If the deadline elapses after the operation has begun, it is allowed
to run to completion.
See the note on this impl block for details.
Source§impl<E> EaseOff<E>
impl<E> EaseOff<E>
Sourcepub fn start_unlimited() -> Self
pub fn start_unlimited() -> Self
Alias for Options::start_unlimited() using Options::DEFAULT.
Sourcepub fn start_timeout(timeout: Duration) -> Self
pub fn start_timeout(timeout: Duration) -> Self
Alias for Options::start_timeout() using Options::DEFAULT.
Sourcepub fn start_timeout_opt(timeout: Option<Duration>) -> Self
pub fn start_timeout_opt(timeout: Option<Duration>) -> Self
Alias for Options::start_timeout_opt() using Options::DEFAULT.
Sourcepub fn start_deadline(deadline: Instant) -> Self
pub fn start_deadline(deadline: Instant) -> Self
Alias for Options::start_deadline() using Options::DEFAULT.
Sourcepub fn start_deadline_opt(deadline: Option<Instant>) -> Self
pub fn start_deadline_opt(deadline: Option<Instant>) -> Self
Alias for Options::start_deadline_opt() using Options::DEFAULT.
Sourcepub fn started_at(&self) -> Instant
pub fn started_at(&self) -> Instant
Returns the Instant when this instance was constructed.
Sourcepub fn deadline(&self) -> Option<Instant>
pub fn deadline(&self) -> Option<Instant>
Returns the deadline, if provided.
If constructed with a timeout, it is converted to a deadline on construction
by adding the timeout to Self::started_at().
Sourcepub fn num_attempts(&self) -> u32
pub fn num_attempts(&self) -> u32
Returns the number of attempts that have been made.
Saturates at u32::MAX.
Source§impl<E> EaseOff<E>
impl<E> EaseOff<E>
Sourcepub fn try_blocking<T>(
&mut self,
op: impl FnOnce() -> Result<T, E>,
) -> ResultWrapper<'_, T, E>
pub fn try_blocking<T>( &mut self, op: impl FnOnce() -> Result<T, E>, ) -> ResultWrapper<'_, T, E>
Attempt a blocking operation.
If the operation previously failed, sleeps for the prescribed backoff period
using std::thread::sleep().
§Note: Behavior at Deadline
Most blocking operations cannot be cancelled once begun, so the deadline, if set, is only checked before attempting the operation.
Generally, the only kinds of blocking operations that support cancellation take an explicit timeout (such as setting a read timeout on a socket).
If you want a blocking operation to be cancelled immediately once the deadline elapses, consult the documentation for the API you are calling to see if timeouts are supported, and if so, how to configure them.