A library that makes signaling between threads more ergonomic than using Condvar directly.
Inspired by the .NET System.Threading.EventWaitHandle API. Uses Condvar and Mutex under the hood to block threads without consuming CPU time.
```rust use std::sync::Arc; use std::time::Duration; use waithandle::{EventWaitHandle, WaitHandle};
// Create a handle and wrap it // in an Arc so we can share ownership // of it with another thread. let handle = Arc::new(EventWaitHandle::new());
// Signal a thread. handle.signal()?;
// Did someone signal us? handle.check()?;
// Wait for 5 seconds or until someone signals us. if handle.wait(Duration::from_secs(5))? { println!("signal received"); } ```
```
cargo run --example simple ```
[WORK] Doing some work...
[WORK] Doing some work...
[WORK] Doing some work...
[WORK] Doing some work...
[WORK] Doing some work...
[WORK] Waiting...
[MAIN] Signaling thread...
[MAIN] Joining thread...
[WORK] Someone told us to shut down!
[MAIN] Done!