Skip to content

Commit 47e4ac6

Browse files
committed
feat: handle ctrl+c gracefully
1 parent 2af9280 commit 47e4ac6

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

player/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ edition.workspace = true
66

77
[dependencies]
88
cpal = "0.15.2"
9-
tokio = { version = "1.28.1", features = ["macros", "rt-multi-thread", "io-util", "sync", "time"] }
9+
tokio = { version = "1.28.1", features = ["macros", "rt-multi-thread", "io-util", "sync", "time", "signal"] }
1010
protocol = { path = "../protocol" }
1111
futures = "0.3.28"
1212
bincode = "1.3.3"

player/src/main.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ async fn main() -> std::io::Result<()> {
5353
std::fs::remove_file(t.state.read().await.preferences.path())?;
5454
}
5555

56-
println!("exiting");
56+
println!("exited gracefully");
5757

5858
Ok(())
5959
}
@@ -186,6 +186,11 @@ impl MainThread {
186186

187187
loop {
188188
tokio::select! {
189+
_ = tokio::signal::ctrl_c() => {
190+
println!("handling ctrl+c");
191+
break;
192+
}
193+
189194
// watch for connection exits
190195
Some(()) = maybe_connection_exited(&self.connection) => {
191196
self.disconnect().await;

0 commit comments

Comments
 (0)