Skip to content

Commit

Permalink
Merge pull request #482 from hatoo/update-monitor
Browse files Browse the repository at this point in the history
Update data receiver
  • Loading branch information
hatoo authored May 5, 2024
2 parents 3186d68 + 602beb8 commit 0b36563
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 37 deletions.
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

0 comments on commit 0b36563

Please sign in to comment.