fix: ctrl+c not exit sometimes

This commit is contained in:
sigoden
2022-06-05 09:22:24 +08:00
parent 5578ee9190
commit 882a9ae716
2 changed files with 62 additions and 65 deletions

View File

@@ -14,10 +14,23 @@ async fn main() {
async fn run() -> BoxResult<()> {
let args = Args::parse(matches())?;
serve(args).await
tokio::select! {
ret = serve(args) => {
ret
},
_ = shutdown_signal() => {
Ok(())
},
}
}
fn handle_err<T>(err: Box<dyn std::error::Error>) -> T {
eprintln!("error: {}", err);
std::process::exit(1);
}
async fn shutdown_signal() {
tokio::signal::ctrl_c()
.await
.expect("Failed to install CTRL+C signal handler")
}