Skip to content

Commit

Permalink
feat:add ctrl-c to server
Browse files Browse the repository at this point in the history
  • Loading branch information
limuy2022 committed Jun 22, 2024
1 parent dd4b534 commit 223c12f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions gdrust/server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@ pub async fn lib_main() -> Result<(), Box<dyn Error>> {
}
}
});
tokio::spawn(async {
match tokio::signal::ctrl_c().await {
Ok(()) => {
eprintln!("Shutdowning...");
exit(0);
}
Err(err) => {
eprintln!("Unable to listen for shutdown signal: {}", err);
// we also shut down in case of error
}
}
});
loop {
print!(">>>");
std::io::stdout().flush().unwrap();
Expand Down

0 comments on commit 223c12f

Please sign in to comment.