FutureTimeout

Trait FutureTimeout 

Source
pub trait FutureTimeout<T>: Future<Output = T> + Sized {
    // Provided method
    fn timeout(self, duration: Duration) -> impl Future<Output = Option<T>> { ... }
}
Expand description

This trait adds a timeout method to all futures.

Provided Methods§

Source

fn timeout(self, duration: Duration) -> impl Future<Output = Option<T>>

This method, implemented for all futures, returns another future which yields None if the inner future takes too long to yield its output.

If the inner future yields in time, its output is in turn yielded in Some(_).

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.

Implementors§

Source§

impl<T, F: Future<Output = T>> FutureTimeout<T> for F