wait_first

Function wait_first 

Source
pub fn wait_first(
    events: Vec<&dyn Event>,
    dur: Duration,
) -> Result<i32, Box<dyn Error>>
Expand description

Waits for the first event to fire and returns the position of the event given

ยงExamples

This example spawns a thread that will set the third event created after a short delay.

The main thread will wait on all three events and return a position of two for the third event of the provided events

 use std::thread::{sleep, spawn};
 use std::time::Duration;
 use win_events::{ManualResetEvent, wait_first};

 let evt0 = ManualResetEvent::new(false);
 let evt1 = ManualResetEvent::new(false);
 let evt2 = ManualResetEvent::new(false);
 let evt_inner = evt2.clone();

 let worker = spawn(move || {
    sleep(Duration::from_millis(10));
    evt_inner.set()
 });

 let wait_result = wait_first(
    vec![&evt0, &evt1, &evt2],
    Duration::from_millis(100),
 ).unwrap();

 assert_eq!(2, wait_result);
 worker.join().unwrap()