pub struct Event(pub(crate) PlatformEvent);
Expand description
An inter-process event wait/notify mechanism. Loosely speaking: Writes signal the event. Reads block until the event is signaled and then clear the signal.
Supports multiple simultaneous writers (i.e. signalers) but only one simultaneous reader (i.e. waiter). The behavior of multiple readers is undefined in cross platform code.
Multiple Event
s can be polled at once via WaitContext
.
Implementation notes:
- Uses eventfd on Linux.
- Uses synchapi event objects on Windows.
- The
Event
andWaitContext
APIs together cannot easily be implemented with the same semantics on all platforms. In particular, it is difficult to support multiple readers, so only a single reader is allowed for now. Multiple readers will result in undefined behavior.
Tuple Fields§
§0: PlatformEvent
Implementations§
source§impl Event
impl Event
sourcepub fn wait(&self) -> Result<()>
pub fn wait(&self) -> Result<()>
Blocks until the event is signaled and clears the signal.
It is undefined behavior to wait on an event from multiple threads or processes simultaneously.
sourcepub fn wait_timeout(&self, timeout: Duration) -> Result<EventWaitResult>
pub fn wait_timeout(&self, timeout: Duration) -> Result<EventWaitResult>
Blocks until the event is signaled and clears the signal, or until the timeout duration expires.
It is undefined behavior to wait on an event from multiple threads or processes simultaneously.
sourcepub fn reset(&self) -> Result<()>
pub fn reset(&self) -> Result<()>
Clears the event without blocking.
If the event is not signaled, this has no effect and returns immediately.
sourcepub fn try_clone(&self) -> Result<Event>
pub fn try_clone(&self) -> Result<Event>
Clones the event. The event’s state is shared between cloned instances.
The documented caveats for Event
also apply to a set of cloned instances, e.g., it is
undefined behavior to clone an event and then call Event::wait
simultaneously on both
objects.
Implementation notes:
- Linux: The cloned instance uses a separate file descriptor.
- Windows: The cloned instance uses a separate handle.