pub trait ReconnectCallback<S: AppState>: Send + Sync {
// Required method
fn call<'life0, 'life1, 'async_trait>(
&'life0 self,
state: Arc<S>,
ws_sender: &'life1 AsyncSender<Message>,
) -> Pin<Box<dyn Future<Output = CoreResult<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
}Expand description
A trait for callback functions that can be executed within the context of a module. This trait is designed to allow modules to define custom behavior that can be executed when a reconnection event occurs.
Required Methods§
Sourcefn call<'life0, 'life1, 'async_trait>(
&'life0 self,
state: Arc<S>,
ws_sender: &'life1 AsyncSender<Message>,
) -> Pin<Box<dyn Future<Output = CoreResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn call<'life0, 'life1, 'async_trait>(
&'life0 self,
state: Arc<S>,
ws_sender: &'life1 AsyncSender<Message>,
) -> Pin<Box<dyn Future<Output = CoreResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
The asynchronous function that will be called when a reconnection event occurs.
This function receives the shared state and a sender for outgoing WebSocket messages.
It should return a CoreResult<()> indicating the success or failure of the operation.
/// # Arguments
state: The shared application state that the callback can use.ws_sender: The sender for outgoing WebSocket messages, allowing the callback to send messages to the WebSocket connection.
§Returns
A CoreResult<()> indicating the success or failure of the operation.
§Note
This function is expected to be asynchronous, allowing it to perform I/O operations or other tasks that may take time without blocking the event loop. Implementations should ensure that they handle any potential errors gracefully and return appropriate results. It is also important to ensure that the callback does not block the event loop, as this could lead to performance issues in the application. Implementations should be designed to be efficient and non-blocking, allowing the application to continue processing other events while the callback is executed. This trait is useful for defining custom behavior that can be executed when a reconnection event occurs, allowing modules to handle reconnections in a flexible and reusable way.