Crates.io | tiny_future |
lib.rs | tiny_future |
version | 0.5.1 |
source | src |
created_at | 2018-06-30 21:18:05.997647 |
updated_at | 2022-08-04 18:15:12.269456 |
description | This library provides a simple, `Condvar` based future with automatic cancellation on drop |
homepage | |
repository | https://github.com/KizzyCode/tiny_future-rust |
max_upload_size | |
id | 72366 |
size | 16,657 |
tiny_future
Welcome to tiny_future
🎉
This library provides a simple, Condvar
based future with automatic cancellation on drop.
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);