Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aib/waitable
https://github.com/aib/waitable
Last synced: 3 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/aib/waitable
- Owner: aib
- Created: 2022-12-27T13:27:12.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2022-12-27T14:41:58.000Z (about 2 years ago)
- Last Synced: 2024-12-20T09:49:22.242Z (25 days ago)
- Language: Rust
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Waitable
A synchronized (atomic) value container implementing the Mutex+Condvar pattern for efficient blocking waits
## Usage
```rust
use std::sync::Arc;
use waitable::Waitable;let w = Arc::new(Waitable::new(0));
println!("Spawning thread...");
let join_handle = {
let w = w.clone();
std::thread::spawn(move || {
println!("Thread waiting...");
w.wait(&42);
println!("Thread done waiting");
})
};println!("Waiting to set...");
std::thread::sleep(std::time::Duration::from_millis(500));println!("Setting...");
w.set(42);join_handle.join().unwrap();
println!("All done");
``````
Spawning thread...
Waiting to set...
Thread waiting...
Setting...
Thread done waiting
All done
```