[][src]Trait smol_timeout::TimeoutExt

pub trait TimeoutExt: Future {
    fn timeout(self, after: Duration) -> Timeout<Self>

Notable traits for Timeout<Fut>

impl<Fut: Future> Future for Timeout<Fut> type Output = Option<Fut::Output>;

    where
        Self: Sized
, { ... } }

An extension trait for Futures that provides a way to create Timeouts.

Provided methods

fn timeout(self, after: Duration) -> Timeout<Self>

Notable traits for Timeout<Fut>

impl<Fut: Future> Future for Timeout<Fut> type Output = Option<Fut::Output>;
where
    Self: Sized

Given a Duration, creates and returns a new Timeout that will poll both the future and a Timer that will complete after the provided duration, and return the future's output or None if the timer completes first.

Example

use async_io::Timer;
use smol_timeout::TimeoutExt;
use std::time::Duration;

let foo = async {
    Timer::after(Duration::from_millis(250)).await;
    24
};

let foo = foo.timeout(Duration::from_millis(100));
assert_eq!(foo.await, None);

let bar = async {
    Timer::after(Duration::from_millis(100)).await;
    42
};

let bar = bar.timeout(Duration::from_millis(250));
assert_eq!(bar.await, Some(42));
Loading content...

Implementors

impl<Fut: Future> TimeoutExt for Fut[src]

Loading content...