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§
Required Methods§
Sourcefn new() -> Self
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.
Sourcefn new_set() -> Self
fn new_set() -> Self
Creates an event in the set state. This means that the event can be immediately acquired.
Sourcefn wait(&'a self) -> Self::Waiter
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.
Sourcefn set_one(&self) -> bool
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.
Sourcefn set_all<F: FnMut()>(&self, functor: F)
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.
Sourcefn try_wait(&self) -> bool
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.
Sourcefn has_waiters(&self) -> bool
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.