Skip to content

Commit

Permalink
Fix potential panic when Stats drops
Browse files Browse the repository at this point in the history
  • Loading branch information
jerry73204 committed Jan 11, 2024
1 parent ef888b9 commit 1f119c6
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion examples/examples/z_sub_thr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ impl Stats {
}
impl Drop for Stats {
fn drop(&mut self) {
let elapsed = self.global_start.unwrap().elapsed().as_secs_f64();
let Some(global_start) = self.global_start else {
return;
};
let elapsed = global_start.elapsed().as_secs_f64();
let total = self.round_size * self.finished_rounds + self.round_count;
let throughtput = total as f64 / elapsed;
println!("Received {total} messages over {elapsed:.2}s: {throughtput}msg/s");
Expand Down

0 comments on commit 1f119c6

Please sign in to comment.