[][src]Crate smol_timeout

smol-timeout

A way to poll a future until it or a smol::Timer completes.

Example

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

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

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

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

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

Structs

Timeout

A future polling both another future and a [Timer] that will complete after a specified timeout, and returning the future's output or None if the timer completes first.

Traits

TimeoutExt

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