Skip to content

Commit

Permalink
fix: Catch ctrl-c signal on windows (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
infiniteregrets authored Dec 5, 2024
1 parent c9dec84 commit 21e9952
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 51 deletions.
24 changes: 0 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ pin-project-lite = "0.2"
pin-utils = "0.1.0"
serde = { version = "1.0.214", features = ["derive"] }
serde_json = "1.0.132"
signal-hook = "0.3.17"
signal-hook-tokio = { version = "0.3.1", features = ["futures-v0_3"] }
thiserror = "1.0.67"
tokio = { version = "1.41.1", features = ["full"] }
tokio-stream = { version = "0.1.16", features = ["io-util"] }
Expand Down
34 changes: 9 additions & 25 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ use clap::{builder::styling, Parser, Subcommand};
use colored::*;
use config::{config_path, create_config};
use error::{S2CliError, ServiceError, ServiceErrorContext};
use signal_hook::consts::{SIGINT, SIGTERM, SIGTSTP};
use signal_hook_tokio::Signals;
use stream::{RecordStream, StreamService};
use streamstore::{
client::{BasinClient, Client, ClientConfig, S2Endpoints, StreamClient},
Expand All @@ -20,6 +18,7 @@ use streamstore::{
},
HeaderValue,
};
use tokio::signal;
use tokio::{
fs::{File, OpenOptions},
io::{self, AsyncBufRead, AsyncBufReadExt, AsyncWrite, AsyncWriteExt, BufReader, BufWriter},
Expand Down Expand Up @@ -573,9 +572,6 @@ async fn run() -> Result<(), S2CliError> {
.lines(),
);

let mut signals =
Signals::new([SIGTSTP, SIGINT, SIGTERM]).expect("valid signals");

let mut append_output_stream = StreamService::new(stream_client)
.append_session(append_input_stream, fencing_token, match_seq_num)
.await?;
Expand Down Expand Up @@ -607,16 +603,11 @@ async fn run() -> Result<(), S2CliError> {
}
}

Some(signal) = signals.next() => {
match signal {
SIGTSTP | SIGINT | SIGTERM => {
drop(append_output_stream);
eprintln!("{}", "■ [ABORTED]".red().bold());
break;
}
_ => {}
_ = signal::ctrl_c() => {
drop(append_output_stream);
eprintln!("{}", "■ [ABORTED]".red().bold());
break;
}
}
}
}
}
Expand All @@ -627,8 +618,6 @@ async fn run() -> Result<(), S2CliError> {
limit_bytes,
} => {
let stream_client = StreamClient::new(client_config, basin, stream);
let mut signals =
Signals::new([SIGTSTP, SIGINT, SIGTERM]).expect("valid signals");
let mut read_output_stream = StreamService::new(stream_client)
.read_session(start_seq_num, limit_count, limit_bytes)
.await?;
Expand Down Expand Up @@ -704,15 +693,10 @@ async fn run() -> Result<(), S2CliError> {
None => break,
}
},
Some(signal) = signals.next() => {
match signal {
SIGTSTP | SIGINT | SIGTERM => {
drop(read_output_stream);
eprintln!("{}", "■ [ABORTED]".red().bold());
break;
}
_ => {}
}
_ = signal::ctrl_c() => {
drop(read_output_stream);
eprintln!("{}", "■ [ABORTED]".red().bold());
break;
}
}
let total_elapsed_time = start.unwrap().elapsed().as_secs_f64();
Expand Down

0 comments on commit 21e9952

Please sign in to comment.