pub struct EventPublisher<E> { /* private fields */ }Expand description
A publish-only handle to a bus.
A publisher has no buffer to fill, so a part that only announces holds one
rather than a BroadcastBus. Cloning it is cheap, and publishing never
waits: a subscriber that falls behind loses events rather than holding up the
publisher.
§Examples
use pamoja_core::EventBus;
use pamoja_bus::EventPublisher;
let power = EventPublisher::new(8);
let mut control = power.subscribe();
let mut logger = power.subscribe();
assert_eq!(power.publish("battery.low"), 2);
assert_eq!(control.next_event().await?, Some("battery.low"));
assert_eq!(logger.next_event().await?, Some("battery.low"));Implementations§
Source§impl<E: Clone> EventPublisher<E>
impl<E: Clone> EventPublisher<E>
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Creates a bus with no subscribers yet, and a publisher on it.
§Arguments
capacity- the per-subscriber buffer depth, rounded up to the next power of two. Values below one are raised to one, and values aboveMAX_CAPACITYare lowered to it.
§Returns
A publisher to take subscribers from and publish to them.
Sourcepub fn subscribe(&self) -> BroadcastBus<E>
pub fn subscribe(&self) -> BroadcastBus<E>
Subscribes to the bus.
§Returns
A handle that receives events published after this call and can also publish.
Sourcepub fn publisher(&self) -> EventPublisher<E>
pub fn publisher(&self) -> EventPublisher<E>
Takes another publisher on the same bus, for another part that announces.
§Returns
A publisher with a lifetime of its own, the same as a clone of this one.
Trait Implementations§
Source§impl<E: Clone> Clone for EventPublisher<E>
impl<E: Clone> Clone for EventPublisher<E>
Source§fn clone(&self) -> EventPublisher<E>
fn clone(&self) -> EventPublisher<E>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<E> Freeze for EventPublisher<E>
impl<E> RefUnwindSafe for EventPublisher<E>
impl<E> Send for EventPublisher<E>where
E: Send,
impl<E> Sync for EventPublisher<E>where
E: Send,
impl<E> Unpin for EventPublisher<E>
impl<E> UnsafeUnpin for EventPublisher<E>
impl<E> UnwindSafe for EventPublisher<E>
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