diff options
author | Tuomas Siipola | 2021-04-15 11:13:53 +0300 |
---|---|---|
committer | Tuomas Siipola | 2021-04-15 11:15:24 +0300 |
commit | 9670b8f5ddbd47fb44c2e1b58f11d27e64115bb1 (patch) | |
tree | e0f7d3f75f6c26cd706e880b4717ee618d097f6d | |
parent | c2458f8536c99ad5fc46a93532e914ef89dde37a (diff) |
-rw-r--r-- | src/main.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs index 2c0403e..9e49f29 100644 --- a/src/main.rs +++ b/src/main.rs @@ -388,6 +388,12 @@ impl App { } } +async fn shutdown_signal() { + tokio::signal::ctrl_c() + .await + .expect("failed to install Ctrl+C signal handler"); +} + #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> { let app = Arc::new(App::new()); @@ -403,7 +409,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> { Err(std::env::VarError::NotUnicode(_)) => panic!("invalid encoding"), }; - let server = Server::bind(&addr).serve(service); + let server = Server::bind(&addr) + .serve(service) + .with_graceful_shutdown(shutdown_signal()); println!("Listening on http://{}", addr); |