urholaukkarinen / notify-thread

A simple wrapper for notifying threads

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

notify-thread

A simple wrapper for threads that allows you to notify the thread that something has happened.

fn main() {
    // Spawn a new thread that waits until notified
    let join_handle = easy_thread::spawn(|ctx| {
        while !ctx.notified() {
            println!("Looping");

            std::thread::sleep(std::time::Duration::from_millis(100));
        }
    });

    std::thread::sleep(std::time::Duration::from_millis(1000));

    // Notify the thread
    join_handle.notify();

    join_handle.join().unwrap();
}

About

A simple wrapper for notifying threads

License:MIT License


Languages

Language:Rust 100.0%