[−][src]Struct piper::Event
A synchronization primitive for notifying async tasks and threads.
Listeners can be registered using [listen()][Event::listen()]. There are two ways of
notifying listeners:
- [
notify_one()][Event::notify_one()] notifies one listener. - [
notify_all()][Event::notify_all()] notifies all listeners.
If there are no active listeners at the time a notification is sent, it simply gets lost.
Note that [notify_one()][Event::notify_one()] does not notify one additional listener -
it only makes sure at least one listener among the active ones is notified.
There are two ways for a listener to wait for a notification:
- In an asynchronous manner using
.await. - In a blocking manner by calling [
wait()][EventListener::wait()] on it.
If a notified listener is dropped without ever waiting for a notification, dropping will notify another another active listener.
Listeners are registered and notified in the first-in first-out fashion, ensuring fairness.
Methods
impl Event[src]
pub fn new() -> Event[src]
Creates a new [Event].
pub fn listen(&self) -> EventListener[src]
Returns a guard listening for a notification.
pub fn notify_one(&self)[src]
Notifies a single active listener.
Note that this does not notify one additional listener - it only makes sure at least one listener among the active ones is notified.
pub fn notify_all(&self)[src]
Notifies all active listeners.
Trait Implementations
Auto Trait Implementations
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,