pub struct Event { /* private fields */ }Expand description
A synchronization primitive for notifying tasks in a single-threaded context.
This is similar to event_listener::Event but uses Rc/RefCell instead
of thread-safe primitives, making it suitable only for single-threaded use.
Implementations§
Source§impl Event
impl Event
Sourcepub fn listen(&self) -> EventListener ⓘ
pub fn listen(&self) -> EventListener ⓘ
Sourcepub fn notify(&self, n: usize)
pub fn notify(&self, n: usize)
Notifies a number of active listeners.
The number of notified listeners is determined by n:
- If
nisusize::MAX, all active listeners are notified. - Otherwise,
nactive listeners are notified.
§Examples
use local_event::Event;
let event = Event::new();
// Notify all listeners.
event.notify(usize::MAX);
// Notify exactly 5 listeners.
event.notify(5);Sourcepub fn notify_additional(&self, n: usize)
pub fn notify_additional(&self, n: usize)
Notifies a number of active and still waiting listeners.
Unlike notify(), this method only notifies listeners that haven’t been
notified yet and are still registered.
§Examples
use local_event::Event;
let event = Event::new();
event.notify_additional(2);Sourcepub fn notify_all(&self)
pub fn notify_all(&self)
Notifies all active listeners.
This is equivalent to calling notify(usize::MAX).
§Examples
use local_event::Event;
let event = Event::new();
let listener1 = event.listen();
let listener2 = event.listen();
// Notify all listeners.
event.notify_all();
assert!(listener1.is_notified());
assert!(listener2.is_notified());Trait Implementations§
Auto Trait Implementations§
impl Freeze for Event
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more