pub trait WithTimeout: Sized {
type Output;
// Required method
fn with_deadline(self, at: Instant) -> TimeoutFuture<Self>;
// Provided methods
fn with_timeout(self, timeout: impl Into<Duration>) -> TimeoutFuture<Self> { ... }
fn try_with_timeout(
self,
timeout: impl Into<Duration>,
) -> Option<TimeoutFuture<Self>> { ... }
}Expand description
Provides functions to run a given future with a timeout or a deadline.
Required Associated Types§
Required Methods§
Sourcefn with_deadline(self, at: Instant) -> TimeoutFuture<Self>
fn with_deadline(self, at: Instant) -> TimeoutFuture<Self>
Runs a given future with a deadline time.
If the future completes before the deadline, its output is returned. Otherwise, on timeout,
work on the future is stopped (poll is no longer called), the future is dropped and Err(TimeoutError) is returned.
Provided Methods§
Sourcefn with_timeout(self, timeout: impl Into<Duration>) -> TimeoutFuture<Self>
fn with_timeout(self, timeout: impl Into<Duration>) -> TimeoutFuture<Self>
Runs a given future with a timeout.
If the future completes before the timeout, its output is returned. Otherwise, on timeout,
work on the future is stopped (poll is no longer called), the future is dropped and Err(TimeoutError) is returned.
§Panics
Panics if the computed instant overflows.
Avoid panics with WithTimeout::try_with_timeout().
Sourcefn try_with_timeout(
self,
timeout: impl Into<Duration>,
) -> Option<TimeoutFuture<Self>>
fn try_with_timeout( self, timeout: impl Into<Duration>, ) -> Option<TimeoutFuture<Self>>
Tries to run a given future with a timeout.
If the future completes before the timeout, its output is returned. Otherwise, on timeout,
work on the future is stopped (poll is no longer called), the future is dropped and Err(TimeoutError) is returned.
This is a panic-free WithTimeout::with_timeout().
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.