cataclysm_ws/
web_socket_thread.rs

1use std::future::Future;
2use crate::Message;
3
4/// Trait necessary to start a ws read-processing thread
5pub trait WebSocketThread: Send + 'static {
6    type Output: Send;
7    /// On opened connection
8    ///
9    /// This function gets called when the websockets connection is properly stablished.
10    fn on_open(&mut self) -> impl Future<Output = ()> + Send {
11        async {}
12    }
13    /// On message callback
14    ///
15    /// This function gets called back when a [Message](crate::Message) is received.
16    fn on_message(&mut self, message: Message) -> impl Future<Output = ()> + Send;
17    
18    /// On closed connection
19    ///
20    /// This function gets called when the websockets connection is closed (either gracefully, or by an error)
21    fn on_close(&mut self, _clean: bool) -> impl Future<Output = Self::Output> + Send;
22}