Crate tiny_future

Source
Expand description

License License AppVeyor CI docs.rs crates.io Download numbers dependency status

§tiny_future

Welcome to tiny_future 🎉

This library provides a simple, Condvar based future with automatic cancellation on drop.

§Example

use std::{thread, time::Duration};

// Create futures
let (setter, getter) = tiny_future::new::<u8>();

// Run something in a separate task
thread::spawn(move || {
    // Do some computations and set the result
    thread::sleep(Duration::from_secs(1));
    setter.set(7);
});

// Wait unil the result is available
let result = getter.wait().expect("Failed to compute result");
assert_eq!(result, 7);

Structs§

Getter
A getter for a future
Setter
A setter for a future

Functions§

new
Creates a new future