temp: impl heartbeathandlercapable

This commit is contained in:
bitfl0wer 2023-11-19 16:43:21 +01:00
parent b3ebdd69fc
commit f4ae80fee9
1 changed files with 37 additions and 1 deletions

View File

@ -1,4 +1,40 @@
use tokio::task::JoinHandle; use tokio::task::{self, JoinHandle};
use ws_stream_wasm::*; use ws_stream_wasm::*;
use super::*; use super::*;
#[async_trait]
impl HeartbeatHandlerCapable<WsMessage, WsStream> for HeartbeatHandler {
fn get_send(&self) -> &Sender<HeartbeatThreadCommunication> {
&self.send
}
fn get_heartbeat_interval(&self) -> Duration {
self.heartbeat_interval
}
fn new(
heartbeat_interval: Duration,
websocket_tx: Arc<Mutex<SplitSink<WsStream, WsMessage>>>,
kill_rc: tokio::sync::broadcast::Receiver<()>,
) -> HeartbeatHandler {
let (send, receive) = tokio::sync::mpsc::channel(32);
let kill_receive = kill_rc.resubscribe();
let handle: JoinHandle<()> = task::spawn(async move {
HeartbeatHandler::heartbeat_task(
websocket_tx,
heartbeat_interval,
receive,
kill_receive,
)
.await;
});
Self {
heartbeat_interval,
send,
handle,
}
}
}