pub struct TryAsync<'a, E, F> { /* private fields */ }async-io-2 or tokio only.Expand description
.awaitable type returned by EaseOff::try_async() and EaseOff::try_async_with().
§Panics
If an async runtime is not available for sleeping between retries.
§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 Self::enforce_deadline_with().
Implementations§
Source§impl<'a, T, E, F, Fut> TryAsync<'a, E, F>
impl<'a, T, E, F, Fut> TryAsync<'a, E, F>
Sourcepub async fn enforce_deadline_with(
self,
make_error: impl FnOnce(Option<E>) -> E,
) -> ResultWrapper<'a, T, E>
pub async fn enforce_deadline_with( self, make_error: impl FnOnce(Option<E>) -> E, ) -> ResultWrapper<'a, T, E>
Cancel the operation as soon as the deadline elapses, if set.
The closure will be called to produce the error that will be returned; if the operation failed on a previous attempt, that error is included.
§Panics
If an async runtime is not available for managing the timeout.
§Example
use std::time::Duration;
use ease_off::EaseOff;
let mut ease_off = EaseOff::start_timeout(Duration::from_secs(5));
let result = ease_off
// An async operation that will never complete.
.try_async(std::future::pending::<Result<String, String>>())
// You may either use the last error (`_e`) or create a new one
.enforce_deadline_with(|_e: Option<String>| "deadline elapsed".to_string())
.await
.or_retry_if(|_e| false);
assert_eq!(result.unwrap_err(), "deadline elapsed");