From 29e78ee652a23da403385959dd618719e21a5c27 Mon Sep 17 00:00:00 2001 From: Paweł Dybiec Date: Sun, 27 Aug 2023 12:50:31 +0100 Subject: Terminate on connection error --- src/main.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 6ea162b..1dc8e63 100644 --- a/src/main.rs +++ b/src/main.rs @@ -113,24 +113,29 @@ async fn main() -> Result<(), Box> { let mut client = mattermost::Client::new(auth, "https://mattermost.continuum.ii.uni.wroc.pl"); client.update_bearer_token().await?; { - let (shutdown_send, shutdown_recv) = tokio::sync::mpsc::unbounded_channel(); + let (shutdown_send, shutdown_recv) = tokio::sync::oneshot::channel(); + let (on_task_finish_send, on_task_finish_recv) = tokio::sync::oneshot::channel(); let websocket_task = tokio::spawn(async move { - client + let result = client .handle_websocket_stream(Vav::new(db), shutdown_recv) - .await + .await; + on_task_finish_send.send(result).unwrap(); }); { let mut sigterm = unix::signal(unix::SignalKind::terminate())?; let mut sigint = unix::signal(unix::SignalKind::interrupt())?; let mut sigquit = unix::signal(unix::SignalKind::quit())?; tokio::select! { - signal = sigterm.recv() => signal, - signal = sigint.recv() => signal, - signal = sigquit.recv() => signal, + _ = sigterm.recv() => {}, + _ = sigint.recv() => {}, + _ = sigquit.recv() => {}, + task_result = on_task_finish_recv => { + warn!("Task closed with result {:?}",task_result); + }, }; } - shutdown_send.send(())?; - websocket_task.await??; + _ = shutdown_send.send(()); + websocket_task.await?; } Ok(()) } -- cgit 1.4.1