diff options
author | Paweł Dybiec <pawel@dybiec.info> | 2022-12-27 17:43:38 +0000 |
---|---|---|
committer | Paweł Dybiec <pawel@dybiec.info> | 2022-12-27 17:50:24 +0000 |
commit | 82e78ef563dc2744c1e135ce0675361960747d4f (patch) | |
tree | 1ea041b958537872628e62eeeca111779d18d45c /src/main.rs | |
parent | Treat missing mentions as empty list (diff) |
Handle shutdown gracefully
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs index c2d2be3..da396c2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -104,6 +104,19 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { let auth = mattermost::AuthData { login, password }; let mut client = mattermost::Client::new(auth, "https://mattermost.continuum.ii.uni.wroc.pl"); client.update_bearer_token().await?; - client.handle_websocket_stream(Vav::new(db)).await?; + { + let (shutdown_send, shutdown_recv) = tokio::sync::mpsc::unbounded_channel(); + let websocket_task =tokio::spawn( async move { + client.handle_websocket_stream(Vav::new(db),shutdown_recv).await}); + match tokio::signal::ctrl_c().await { + Ok(()) => {}, + Err(err) => { + eprintln!("Unable to listen for shutdown signal: {}", err); + // we also shut down in case of error + }, + } + shutdown_send.send(())?; + websocket_task.await??; + } Ok(()) } |