#automatic #future #cancellation #condvar #drop #thread #duration

tiny_future

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

6 releases

0.5.1 Aug 4, 2022
0.5.0 Jul 30, 2022
0.4.0 Dec 8, 2020
0.3.2 Sep 12, 2018
0.3.0 Jun 30, 2018

#762 in Asynchronous

BSD-2-Clause OR MIT

9KB
114 lines

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);

No runtime deps