Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update data receiver #482

Merged
merged 2 commits into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 8 additions & 20 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,29 +452,17 @@ async fn main() -> anyhow::Result<()> {
// When `--no-tui` is enabled, just collect all data.
tokio::spawn(
async move {
let (ctrl_c_tx, ctrl_c_rx) = flume::unbounded();

tokio::spawn(async move {
if let Ok(()) = tokio::signal::ctrl_c().await {
let _ = ctrl_c_tx.send(());
}
});

let mut all: ResultData = Default::default();
loop {
tokio::select! {
report = result_rx.recv_async() => {
if let Ok(report) = report {
tokio::select! {
_ = async {
while let Ok(report) = result_rx.recv_async().await {
all.push(report);
} else {
break;
}
}
_ = ctrl_c_rx.recv_async() => {
// User pressed ctrl-c.
let _ = printer::print_result(&mut std::io::stdout(),print_mode,start, &all, start.elapsed(), opts.disable_color, opts.stats_success_breakdown);
std::process::exit(libc::EXIT_SUCCESS);
}
} => {}
_ = tokio::signal::ctrl_c() => {
// User pressed ctrl-c.
let _ = printer::print_result(&mut std::io::stdout(),print_mode,start, &all, start.elapsed(), opts.disable_color, opts.stats_success_breakdown);
std::process::exit(libc::EXIT_SUCCESS);
}
}
all
Expand Down
28 changes: 11 additions & 17 deletions src/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crossterm::{
event::{Event, KeyCode, KeyEvent, KeyModifiers},
ExecutableCommand,
};
use flume::TryRecvError;
use hyper::http;
use ratatui::{
backend::CrosstermBackend,
Expand Down Expand Up @@ -94,24 +93,19 @@ impl Monitor {
colors.set_colors();
}

'outer: loop {
loop {
let frame_start = std::time::Instant::now();
loop {
match self.report_receiver.try_recv() {
Ok(report) => {
if let Ok(report) = report.as_ref() {
*status_dist.entry(report.status).or_default() += 1;
}
all.push(report);
}
Err(TryRecvError::Empty) => {
break;
}
Err(TryRecvError::Disconnected) => {
// Application ends.
break 'outer;
}
let is_disconnected = self.report_receiver.is_disconnected();

for report in self.report_receiver.drain() {
if let Ok(report) = report.as_ref() {
*status_dist.entry(report.status).or_default() += 1;
}
all.push(report);
}

if is_disconnected {
break;
}

let now = std::time::Instant::now();
Expand Down