Skip to main content

SubscriptionLifecycle

Trait SubscriptionLifecycle 

Source
pub trait SubscriptionLifecycle:
    Send
    + Sync
    + 'static {
    // Provided methods
    fn on_connect<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        _params: &'life1 Value,
        _connection_id: &'life2 str,
    ) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn on_disconnect<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _connection_id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn on_subscribe<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        _subscription_name: &'life1 str,
        _variables: &'life2 Value,
        _connection_id: &'life3 str,
    ) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait { ... }
    fn on_unsubscribe<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        _subscription_id: &'life1 str,
        _connection_id: &'life2 str,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
}
Expand description

Callbacks for subscription lifecycle events.

All methods have default no-op implementations, so you only need to override the hooks you care about.

§Fail-closed vs fire-and-forget

  • on_connect / on_subscribe are fail-closed: returning Err(reason) rejects the connection or subscription.
  • on_disconnect / on_unsubscribe are fire-and-forget: the connection is already closing and there is nothing to reject.

Provided Methods§

Source

fn on_connect<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _params: &'life1 Value, _connection_id: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Called after connection_init is received, before connection_ack.

Return Err(reason) to reject the connection with close code 4400.

Source

fn on_disconnect<'life0, 'life1, 'async_trait>( &'life0 self, _connection_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called when the WebSocket connection closes (for any reason).

Source

fn on_subscribe<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, _subscription_name: &'life1 str, _variables: &'life2 Value, _connection_id: &'life3 str, ) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Called before a subscription is registered with the manager.

Return Err(reason) to reject the subscription (the connection stays open).

Source

fn on_unsubscribe<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _subscription_id: &'life1 str, _connection_id: &'life2 str, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Called when a client sends complete for a subscription.

Implementors§