pub struct BroadcastManager { /* private fields */ }Expand description
Manages named broadcast channels.
Thread-safe via interior mutability (RwLock for channel map, atomics for counters).
Implementations§
Source§impl BroadcastManager
impl BroadcastManager
Sourcepub fn new(config: BroadcastConfig) -> Self
pub fn new(config: BroadcastConfig) -> Self
Create a new broadcast manager.
Sourcepub async fn publish(
&self,
channel: &str,
event: String,
payload: Value,
) -> Result<usize, BroadcastError>
pub async fn publish( &self, channel: &str, event: String, payload: Value, ) -> Result<usize, BroadcastError>
Publish a message to a named channel.
Creates the channel if it doesn’t exist. Returns the number of receivers that were notified (0 if nobody is listening).
§Errors
Returns error if the channel limit is exceeded or the payload is too large.
Sourcepub async fn subscribe(
&self,
channel: &str,
) -> Result<Receiver<BroadcastMessage>, BroadcastError>
pub async fn subscribe( &self, channel: &str, ) -> Result<Receiver<BroadcastMessage>, BroadcastError>
Subscribe to a named channel. Creates the channel if it doesn’t exist.
§Errors
Returns error if the channel limit is exceeded.
Sourcepub async fn gc_empty_channels(&self) -> usize
pub async fn gc_empty_channels(&self) -> usize
Remove channels with no active subscribers to prevent memory leaks.
Sourcepub async fn stats(&self) -> BroadcastStats
pub async fn stats(&self) -> BroadcastStats
Get current broadcast statistics.
Sourcepub async fn channel_count(&self) -> usize
pub async fn channel_count(&self) -> usize
Get the number of active channels.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for BroadcastManager
impl !RefUnwindSafe for BroadcastManager
impl Send for BroadcastManager
impl Sync for BroadcastManager
impl Unpin for BroadcastManager
impl UnsafeUnpin for BroadcastManager
impl UnwindSafe for BroadcastManager
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
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more