Crates.io | future-bool |
lib.rs | future-bool |
version | 0.1.1 |
source | src |
created_at | 2021-08-01 20:57:07.255975 |
updated_at | 2021-08-01 21:15:07.765384 |
description | A bool one can await the changes. |
homepage | |
repository | https://github.com/devalain/future-bool |
max_upload_size | |
id | 430152 |
size | 18,772 |
A bool one can await
the changes.
use future_bool::FutureBool;
#[tokio::main]
async fn main() {
let run = FutureBool::new(false);
let run_clone = run.clone();
let task = tokio::spawn(async move {
loop {
// If run changes to false before `some_async_fn` is terminated,
// it will be interrupted.
tokio::select! {
_ = run_clone.wait_false() => break,
_ = some_async_fn() => {}
};
}
});
// ... some other task sets run to false with
// `run.unset()`
task.await;
}