signals
This commit is contained in:
3 files changed
+41
-2
No files matched your search
+19
-1
@@ -53,6 +53,24 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let port = std::env::var("PORT").unwrap_or_else(|_| "3000".to_owned());
|
||||
let listener = TcpListener::bind(format!("0.0.0.0:{port}")).await?;
|
||||
println!("Listening on http://localhost:{port}");
|
||||
serve(listener, app).await?;
|
||||
serve(listener, app)
|
||||
.with_graceful_shutdown(shutdown_signal())
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn shutdown_signal() {
|
||||
let terminate = async {
|
||||
tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate())
|
||||
.expect("Failed to install SIGTERM handler")
|
||||
.recv()
|
||||
.await;
|
||||
};
|
||||
|
||||
tokio::select! {
|
||||
result = tokio::signal::ctrl_c() => {
|
||||
result.expect("Failed to install Ctrl+C handler");
|
||||
}
|
||||
_ = terminate => {}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user