summary refs log tree commit diff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs21
1 files changed, 13 insertions, 8 deletions
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<dyn std::error::Error>> {
     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(())
 }