pub struct Broadcaster<T> { /* private fields */ }Expand description
A bounded, cancellable fan-out broadcaster.
Cheaply cloneable; every clone shares the same subscriber set,
so an event broadcast through any clone reaches all live subscribers.
T must be Clone (each subscriber receives its own copy)
and Send + 'static to cross the per-subscriber channel.
Implementations§
Source§impl<T> Broadcaster<T>
impl<T> Broadcaster<T>
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a broadcaster with the DEFAULT_BROADCAST_BUFFER per-subscriber buffer.
Sourcepub fn with_buffer(buffer: usize) -> Self
pub fn with_buffer(buffer: usize) -> Self
Create a broadcaster with an explicit per-subscriber buffer.
A buffer of zero is clamped to one so every subscriber can hold at least one in-flight event.
Source§impl<T> Broadcaster<T>
impl<T> Broadcaster<T>
Sourcepub fn subscriber_count(&self) -> usize
pub fn subscriber_count(&self) -> usize
The number of currently registered subscribers.
Disconnected subscribers are pruned lazily on broadcast,
so this count may transiently include subscribers whose streams have been dropped but not
yet pruned.
Sourcepub fn subscribe(&self, cancel: CancellationToken) -> BroadcastStream<T>where
T: Send + 'static,
pub fn subscribe(&self, cancel: CancellationToken) -> BroadcastStream<T>where
T: Send + 'static,
Register a new subscriber and return its bounded, cancellable stream.
The returned stream yields events broadcast after subscription and terminates once cancel fires
or the broadcaster is dropped.
Pass a fresh CancellationToken when no external cancellation is required.