Skip to content

Commit

Permalink
fixed the unwrap evil in observer example
Browse files Browse the repository at this point in the history
  • Loading branch information
Shreyan11 committed Sep 29, 2024
1 parent be2444e commit 84db61d
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions examples/observer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use argmin::core::{ArgminFloat, CostFunction, Error, Executor, PopulationState,
use argmin::solver::particleswarm::{Particle, ParticleSwarm};
use argmin_testfunctions::himmelblau;
use gnuplot::{Color, PointSize};
use std::error;
use std::sync::Mutex;

/// Visualize iterations of a solver for cost functions of type
Expand Down Expand Up @@ -71,7 +72,13 @@ impl Visualizer3d {
/// Draw
fn draw(&mut self) {
// TODO: unwrap evil
let mut figure = self.fg.lock().unwrap();
let mut figure = match self.fg.lock() {
Ok(guard) => guard,
Err(poisoned) => {
println!("Mutex is poisoned: {}", poisoned);
poisoned.into_inner()
}
};

figure.clear_axes();

Expand Down Expand Up @@ -106,8 +113,11 @@ impl Visualizer3d {
)
.set_view(30.0, 30.0); // TODO: do not reset view on new iteration

// TODO: unwrap evil
figure.show().unwrap();

figure.show().unwrap_or_else(|error|{
println!("Error occured while displaying the figure{}\n", error);

Check warning on line 118 in examples/observer/src/main.rs

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"occured" should be "occurred".

});

if let Some(delay) = self.delay {
std::thread::sleep(delay);
Expand Down

0 comments on commit 84db61d

Please sign in to comment.