pub struct PubSubManager { /* private fields */ }Expand description
Topic-based publish/subscribe manager.
Thread-safe manager for real-time subscriptions. Supports topic-based subscriptions, automatic channel creation, and broadcast to all subscribers.
Implementations§
Source§impl PubSubManager
impl PubSubManager
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Create a new PubSubManager with specified channel capacity.
Sourcepub fn with_default_capacity() -> Self
pub fn with_default_capacity() -> Self
Create a new PubSubManager with default capacity (256).
Sourcepub async fn subscribe(&self, topic: &str) -> Receiver<SubscriptionMessage>
pub async fn subscribe(&self, topic: &str) -> Receiver<SubscriptionMessage>
Subscribe to a topic. Returns a receiver for messages.
Sourcepub async fn publish(&self, topic: &str, message: SubscriptionMessage) -> usize
pub async fn publish(&self, topic: &str, message: SubscriptionMessage) -> usize
Publish a message to a topic. Returns number of recipients.
Sourcepub async fn notify_update(&self, table: &str, id: &str, data: &Value)
pub async fn notify_update(&self, table: &str, id: &str, data: &Value)
Notify subscribers of a record update (publishes to record and table topics). Short-circuits with zero allocation if no subscribers exist.
Sourcepub async fn notify_delete(&self, table: &str, id: &str)
pub async fn notify_delete(&self, table: &str, id: &str)
Notify subscribers of a record deletion. Short-circuits with zero allocation if no subscribers exist.
Sourcepub async fn notify_publish(&self, topic: &str, data: Value)
pub async fn notify_publish(&self, topic: &str, data: Value)
Notify subscribers of a custom published message. Short-circuits if no subscribers exist for this topic.
Sourcepub async fn topic_count(&self) -> usize
pub async fn topic_count(&self) -> usize
Get the number of active topics.
Sourcepub fn has_topics(&self) -> bool
pub fn has_topics(&self) -> bool
Whether any subscription topic is live. Cheap (DashMap::is_empty),
sync — callers on a write hot path gate record decode/notify behind
this so a write with no subscribers pays a single atomic-load check.
Sourcepub async fn subscriber_count(&self, topic: &str) -> usize
pub async fn subscriber_count(&self, topic: &str) -> usize
Get the number of subscribers for a topic.
Sourcepub async fn remove_topic(&self, topic: &str) -> bool
pub async fn remove_topic(&self, topic: &str) -> bool
Remove a topic. Returns true if it existed.
Sourcepub async fn cleanup_empty_topics(&self) -> usize
pub async fn cleanup_empty_topics(&self) -> usize
Remove topics with zero active subscribers.
Trait Implementations§
Source§impl Clone for PubSubManager
impl Clone for PubSubManager
Source§fn clone(&self) -> PubSubManager
fn clone(&self) -> PubSubManager
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more