pub struct WaitContext<T: EventToken>(pub(crate) EventContext<T>);
Expand description

Used to wait for multiple objects which are eligible for waiting.

Example

use base::{Event, EventToken, Result, WaitContext};

#[derive(EventToken, Copy, Clone, Debug, PartialEq, Eq)]
enum ExampleToken {
   SomeEvent(u32),
   AnotherEvent,
}

let evt1 = Event::new()?;
let evt2 = Event::new()?;
let another_evt = Event::new()?;

let ctx: WaitContext<ExampleToken> = WaitContext::build_with(&[
    (&evt1, ExampleToken::SomeEvent(1)),
    (&evt2, ExampleToken::SomeEvent(2)),
    (&another_evt, ExampleToken::AnotherEvent),
])?;

// Trigger one of the `SomeEvent` events.
evt2.signal()?;

// Wait for an event to fire. `wait()` will return immediately in this example because `evt2`
// has already been triggered, but in normal use, `wait()` will block until at least one event
// is signaled by another thread or process.
let events = ctx.wait()?;
let tokens: Vec<ExampleToken> = events.iter().filter(|e| e.is_readable)
    .map(|e| e.token).collect();
assert_eq!(tokens, [ExampleToken::SomeEvent(2)]);

// Reset evt2 so it doesn't trigger again in the next `wait()` call.
let _ = evt2.reset()?;

// Trigger a different event.
another_evt.signal()?;

let events = ctx.wait()?;
let tokens: Vec<ExampleToken> = events.iter().filter(|e| e.is_readable)
    .map(|e| e.token).collect();
assert_eq!(tokens, [ExampleToken::AnotherEvent]);

let _ = another_evt.reset()?;

Tuple Fields§

§0: EventContext<T>

Implementations§

Creates a new WaitContext.

Creates a new WaitContext with the the associated triggers.

Adds a trigger to the WaitContext.

Adds a trigger to the WaitContext watching for a specific type of event

Adds multiple triggers to the WaitContext.

Modifies a trigger already added to the WaitContext. If the descriptor is already registered, its associated token will be updated.

Removes the given handle from triggers registered in the WaitContext if present.

Waits for one or more of the registered triggers to become signaled.

Waits for one or more of the registered triggers to become signaled, failing if no triggers are signaled before the designated timeout has elapsed.

Trait Implementations§

Returns the underlying raw descriptor. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Returns the underlying raw descriptors. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.