pub struct StreamBroadcaster { /* private fields */ }Expand description
A broadcast publisher for raw SSE strings.
StreamBroadcaster is cheap to clone — all clones share the same underlying
broadcast::Sender. Each subscriber gets its own broadcast::Receiver
from subscribe.
The capacity parameter controls the internal ring-buffer size. Slow
subscribers that fall more than capacity messages behind will receive a
[broadcast::error::RecvError::Lagged] error on the next recv() call;
the broadcaster itself is never blocked.
Implementations§
Source§impl StreamBroadcaster
impl StreamBroadcaster
Sourcepub fn new(capacity: usize) -> Result<Self, AgentRuntimeError>
pub fn new(capacity: usize) -> Result<Self, AgentRuntimeError>
Create a new broadcaster with the given channel capacity.
§Errors
Returns Err if capacity is zero (the broadcast channel requires a
capacity of at least 1).
Sourcepub fn send(&self, sse_line: String) -> Result<usize, AgentRuntimeError>
pub fn send(&self, sse_line: String) -> Result<usize, AgentRuntimeError>
Publish a raw SSE-formatted string to all active subscribers.
Returns the number of active receivers that received the message.
A return value of 0 simply means there are no subscribers at this
moment; it is not an error.
Sourcepub fn send_event(&self, event: &AgentEvent) -> Result<usize, AgentRuntimeError>
pub fn send_event(&self, event: &AgentEvent) -> Result<usize, AgentRuntimeError>
Publish an AgentEvent by converting it to SSE format first.
Sourcepub fn subscribe(&self) -> Receiver<String>
pub fn subscribe(&self) -> Receiver<String>
Create a new subscriber receiver.
The receiver will see all messages published after this call.
Sourcepub fn receiver_count(&self) -> usize
pub fn receiver_count(&self) -> usize
Return the number of active subscribers.
Trait Implementations§
Source§impl Clone for StreamBroadcaster
impl Clone for StreamBroadcaster
Source§fn clone(&self) -> StreamBroadcaster
fn clone(&self) -> StreamBroadcaster
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more