EventSetter

Trait EventSetter 

Source
pub trait EventSetter<'a> {
    type Waiter: Future<Output = ()> + 'a + Unpin;

    // Required methods
    fn new() -> Self;
    fn new_set() -> Self;
    fn wait(&'a self) -> Self::Waiter;
    fn set_one(&self) -> bool;
    fn set_all<F: FnMut()>(&self, functor: F);
    fn try_wait(&self) -> bool;
    fn has_waiters(&self) -> bool;
}
Expand description

Describes an event interface that can be created in a set or unset state and can be waited upon.

Implementing this wrong in and of itself will not cause any undefined behaviour, but great caution should be taken in which events you rely on for your asynchronous primitives.

For instance, if you are writing a mutex and are depending on an unsound implementation of an EventSetter, this could cause immediate and catastrophic undefined behaviour.

Required Associated Types§

Source

type Waiter: Future<Output = ()> + 'a + Unpin

The future representing a pending acquisition of the event.

Required Methods§

Source

fn new() -> Self

Creates a new event in the unset state. This is the expected mode of operation for most events, and means that if a task begins waiting, they will wait until the event is set.

Source

fn new_set() -> Self

Creates an event in the set state. This means that the event can be immediately acquired.

Source

fn wait(&'a self) -> Self::Waiter

Waits on the event. This returns a future which when polled will wait for the event to be acquired.

Source

fn set_one(&self) -> bool

Sets the event. This will wake up any events from the queue if any are pending. This returns a boolean if we were able to actually wake up an event or not.

Source

fn set_all<F: FnMut()>(&self, functor: F)

Sets the event and wakes up all events from the queue if they are pending with the functor. This functor allows more advanced book-keeping per event, for instance with counted events.

Source

fn try_wait(&self) -> bool

Will try to immediately acquire the event along the fast path. This method is non-blocking and will return true if we could acquire the event, and false if we cannot. This will clear the set flag.

Source

fn has_waiters(&self) -> bool

If the event has any pending waiters.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<'a> EventSetter<'a> for Event

Source§

impl<'a> EventSetter<'a> for LocalEvent

Source§

impl<'a, E> EventSetter<'a> for CountedEvent<E>
where E: EventSetter<'a> + 'a,

Source§

type Waiter = CountedAwaiter<'a, E, <E as EventSetter<'a>>::Waiter>