Skip to content

devalain/future-bool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

future-bool

crate docs

A bool one can await the changes.

Example usage

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages