Struct cros_async::Event

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 Events can be polled at once via WaitContext.

Implementation notes:

  • Uses eventfd on Linux.
  • Uses synchapi event objects on Windows.
  • The Event and WaitContext 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§

§

impl Event

pub fn new() -> Result<Event, Error>

Creates new event in an unsignaled state.

pub fn signal(&self) -> Result<(), Error>

Signals the event.

pub fn wait(&self) -> Result<(), Error>

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.

pub fn wait_timeout(&self, timeout: Duration) -> Result<EventWaitResult, Error>

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.

pub fn reset(&self) -> Result<(), Error>

Clears the event without blocking.

If the event is not signaled, this has no effect and returns immediately.

pub fn try_clone(&self) -> Result<Event, Error>

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.

Trait Implementations§

§

impl AsRawDescriptor for Event

§

fn as_raw_descriptor(&self) -> i32

Returns the underlying raw descriptor. Read more
§

impl Debug for Event

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl<'de> Deserialize<'de> for Event

§

fn deserialize<__D>( __deserializer: __D ) -> Result<Event, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
§

impl EventExt for Event

§

fn write_count(&self, v: u64) -> Result<(), Error>

Adds v to the eventfd’s count, blocking until this won’t overflow the count.
§

fn read_count(&self) -> Result<u64, Error>

Blocks until the the eventfd’s count is non-zero, then resets the count to zero.
§

impl From<SafeDescriptor> for Event

§

fn from(sd: SafeDescriptor) -> Event

Converts to this type from the input type.
§

impl FromRawDescriptor for Event

§

unsafe fn from_raw_descriptor(descriptor: i32) -> Event

Safety Read more
§

impl IntoRawDescriptor for Event

§

impl PartialEq for Event

§

fn eq(&self, other: &Event) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl Serialize for Event

§

fn serialize<__S>( &self, __serializer: __S ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
§

impl Eq for Event

source§

impl IntoAsync for Event

§

impl StructuralPartialEq for Event

Auto Trait Implementations§

§

impl RefUnwindSafe for Event

§

impl Send for Event

§

impl Sync for Event

§

impl Unpin for Event

§

impl UnwindSafe for Event

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> AsRawDescriptors for T
where T: AsRawDescriptor,

§

fn as_raw_descriptors(&self) -> Vec<i32>

Returns the underlying raw descriptors. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,