wstd

Module future

Source
Expand description

Asynchronous values.

§Cancellation

Futures can be cancelled by dropping them before they finish executing. This is useful when we’re no longer interested in the result of an operation, as it allows us to stop doing needless work. This also means that a future may cancel at any .await point, and so just like with ? we have to be careful to roll back local state if our future halts there.

use futures_lite::prelude::*;
use wstd::prelude::*;
use wstd::time::Duration;

#[wstd::main]
async fn main() {
    let mut counter = 0;
    let value = async { "meow" }
        .delay(Duration::from_millis(100))
        .timeout(Duration::from_millis(200))
        .await;

    assert_eq!(value.unwrap(), "meow");
}

Structs§

  • Suspends a future until the specified deadline.
  • A future that times out after a duration of time.

Traits§

  • Extend Future with time-based operations.