pub struct NotificationDispatcher { /* private fields */ }Expand description
A notification dispatcher that routes PG notifications to subscribers.
Wraps a tokio broadcast channel. Multiple receivers can subscribe, and each receives all notifications. Used internally by the listener to fan out notifications from a single dedicated connection.
Implementations§
Source§impl NotificationDispatcher
impl NotificationDispatcher
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a new dispatcher with a specific buffer capacity.
Sourcepub fn subscribe(&self) -> NotificationReceiver
pub fn subscribe(&self) -> NotificationReceiver
Subscribe to receive notifications.
Returns a receiver that will get all notifications dispatched after this point.
Sourcepub fn dispatch(&self, notification: Notification) -> usize
pub fn dispatch(&self, notification: Notification) -> usize
Dispatch a notification to all subscribers.
Returns the number of receivers that got the message. Returns 0 if there are no active subscribers (which is fine).
Sourcepub fn add_channel(&mut self, channel: String)
pub fn add_channel(&mut self, channel: String)
Track that we’re listening on a channel.
Sourcepub fn remove_channel(&mut self, channel: &str)
pub fn remove_channel(&mut self, channel: &str)
Remove a tracked channel.
Sourcepub fn channels(&self) -> &HashSet<String>
pub fn channels(&self) -> &HashSet<String>
Get all tracked channel names (for re-subscribing on reconnect).
Sourcepub fn subscriber_count(&self) -> usize
pub fn subscriber_count(&self) -> usize
Number of active subscribers.