pub fn wait_one(
event: &dyn Event,
dur: Duration,
) -> Result<bool, Box<dyn Error>>Expand description
Waits for a single event to be fired
§Examples
This example spawns a thread that will set the event of the created event after a short delay.
The main thread will wait on the event and return true if it’s been set, otherwise it will timeout and return false
use std::thread::{sleep, spawn};
use std::time::Duration;
use win_events::{ManualResetEvent, wait_one};
let evt0 = ManualResetEvent::new(false);
let evt_inner = evt0.clone();
let worker = spawn(move || {
sleep(Duration::from_millis(10));
evt_inner.set()
});
let wait_result = wait_one(
&evt0,
Duration::from_millis(100),
).unwrap();
assert_eq!(true, wait_result);
worker.join().unwrap()