waithandle-rs
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.
Usage
use Arc;
use Duration;
use ;
// Create a handle and wrap it
// in an Arc so we can share ownership
// of it with another thread.
let handle = new;
// Signal a thread.
handle.signal?;
// Did someone signal us?
handle.check?;
// Wait for 5 seconds or until someone signals us.
if handle.wait?
Running the example
> 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!