patriksvensson / waithandle-rs

A library that makes signaling between threads more ergonomic.

Home Page:https://crates.io/crates/waithandle

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Waithandle

A Rust library that makes signaling between threads a bit more ergonomic.

Uses Condvar and Mutex under the hood to block threads without consuming CPU time.

Usage

use std::time::Duration;

// Create the signaler and the listener
let (signaler, listener) = waithandle::new();

// Signal a thread
signaler.signal();

// Did someone signal us?
if listener.check() {
    println!("signal received");
}

// Wait for 5 seconds or until someone signals us
if listener.wait(Duration::from_secs(5)) {
    println!("signal received");
}

Running the example

> cargo run --example simple
Doing some work...
Doing some work...
Doing some work...
Doing some work...
Doing some work...
Signaling thread...
Joining thread...
Someone told us to exit!
Done!

Running benchmarks

> cargo bench

About

A library that makes signaling between threads more ergonomic.

https://crates.io/crates/waithandle

License:MIT License


Languages

Language:Rust 100.0%