Skip to main content

SubscriptionHandler

Trait SubscriptionHandler 

Source
pub trait SubscriptionHandler<R>
where R: Clone + Send + 'static,
{ // Required methods fn subscribe<'life0, 'async_trait>( &'life0 mut self, topic: String, respond_to: SubscriptionResponseTx, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn subscribe_with_filter<'life0, 'async_trait>( &'life0 mut self, topic: String, filter: Box<dyn SubscriptionFilter<R> + Send + Sync>, respond_to: SubscriptionResponseTx, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn unsubscribe<'life0, 'async_trait>( &'life0 mut self, id: usize, respond_to: SubscriptionResponseTx, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn broadcast<'life0, 'async_trait>( &'life0 self, topic: String, message: R, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; }
Expand description

A trait that defines the behavior for handling subscriptions. The intended use is for async nodes to register and manage subscriptions in a generic way.

Required Methods§

Source

fn subscribe<'life0, 'async_trait>( &'life0 mut self, topic: String, respond_to: SubscriptionResponseTx, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Subscribe to a topic or event. Any message broadcast to the topic will be sent to the subscriber.

§Parameters
  • topic: The topic or event to subscribe to.
  • subscription_information: Information related to the subscription.
  • broadcast_tx: The broadcast channel to send messages to the subscriber.
  • respond_to: The channel to send a response to acknowledge the subscription.
Source

fn subscribe_with_filter<'life0, 'async_trait>( &'life0 mut self, topic: String, filter: Box<dyn SubscriptionFilter<R> + Send + Sync>, respond_to: SubscriptionResponseTx, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Subscribe to a topic or event with a filter. The filter will be used to determine if a message should be sent to the subscriber when an event on the topic occurs.

§Parameters
  • topic: The topic or event to subscribe to.
  • subscription_information: Information related to the subscription.
  • filter: The filter to apply to the subscription.
  • broadcast_tx: The broadcast channel to send messages to the subscriber.
  • respond_to: The channel to send a response to acknowledge the subscription.
Source

fn unsubscribe<'life0, 'async_trait>( &'life0 mut self, id: usize, respond_to: SubscriptionResponseTx, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Unsubscribe from a topic or event.

§Parameters
  • topic: The topic or event to unsubscribe from.
  • subscription_information: Information related to the subscription.
  • respond_to: The channel to send a response to acknowledge the unsubscription.
Source

fn broadcast<'life0, 'async_trait>( &'life0 self, topic: String, message: R, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Broadcast a message to all subscribers of a topic.

§Parameters
  • topic: The topic to broadcast the message to.
  • message: The message to broadcast.
§Returns
  • Result<(), anyhow::Error>: Returns an error if the broadcast fails.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<R> SubscriptionHandler<R> for SubscriptionManager<R>
where R: Clone + Send + Sync + 'static,