mirror of
https://github.com/thilo-behnke/wasm-pong.git
synced 2026-08-18 04:36:14 +00:00
graceful shutdown
This commit is contained in:
+9
-2
@@ -20,12 +20,19 @@ impl HttpServer {
|
||||
let host = (self.addr, self.port).into();
|
||||
let server = Server::bind(&host).serve(make_svc);
|
||||
println!("Listening on http://{}", host);
|
||||
server.await?;
|
||||
let graceful = server.with_graceful_shutdown(shutdown_signal());
|
||||
graceful.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async fn handle_request(req: Request<Body>) -> Result<Response<Body>, Infallible> {
|
||||
Ok(Response::new("hello".into()))
|
||||
}
|
||||
|
||||
async fn shutdown_signal() {
|
||||
// Wait for the CTRL+C signal
|
||||
tokio::signal::ctrl_c()
|
||||
.await
|
||||
.expect("failed to install CTRL+C signal handler");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user