From 69c3db69fa4fda8e1712e79ea8833e0a6e7d5680 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 2 Nov 2022 12:54:39 +0100 Subject: [PATCH 1/5] Print message, if change in model is detected --- crates/fj-host/src/evaluator.rs | 7 +++++++ crates/fj-window/src/run.rs | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/crates/fj-host/src/evaluator.rs b/crates/fj-host/src/evaluator.rs index 9e1a65fba..00a1f96fb 100644 --- a/crates/fj-host/src/evaluator.rs +++ b/crates/fj-host/src/evaluator.rs @@ -18,6 +18,10 @@ impl Evaluator { thread::spawn(move || { while let Ok(TriggerEvaluation) = trigger_rx.recv() { + event_tx + .send(ModelEvent::ChangeDetected) + .expect("Expected channel to never disconnect"); + let evaluation = match model.evaluate() { Ok(evaluation) => evaluation, Err(err) => { @@ -60,6 +64,9 @@ pub struct TriggerEvaluation; /// An event emitted by [`Evaluator`] pub enum ModelEvent { + /// A change in the model has been detected + ChangeDetected, + /// The model has been evaluated Evaluation(Evaluation), diff --git a/crates/fj-window/src/run.rs b/crates/fj-window/src/run.rs index 759a58f22..0c5587785 100644 --- a/crates/fj-window/src/run.rs +++ b/crates/fj-window/src/run.rs @@ -69,6 +69,11 @@ pub fn run( }; match event { + ModelEvent::ChangeDetected => { + status.update_status( + "Change in model detected. Compiling...", + ); + } ModelEvent::Evaluation(evaluation) => { status.update_status(&format!( "Model compiled successfully in {}!", From 2b5f7dbc58ece89c12834775283af457019ecd03 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 2 Nov 2022 12:59:04 +0100 Subject: [PATCH 2/5] Print higher-resolution time in status messages --- crates/fj-viewer/src/status_report.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/fj-viewer/src/status_report.rs b/crates/fj-viewer/src/status_report.rs index b78cf9238..a2055f3ec 100644 --- a/crates/fj-viewer/src/status_report.rs +++ b/crates/fj-viewer/src/status_report.rs @@ -20,7 +20,7 @@ impl StatusReport { pub fn update_status(&mut self, status: &str) { let date = { let date = Local::now(); - format!("{}", date.format("[%H:%M:%S]")) + format!("{}", date.format("[%H:%M:%S.%3f]")) }; let empty_space = " ".repeat(date.chars().count()); From 86f9795e41d9e31819c23e9e135e5ecc73c2ae4e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 2 Nov 2022 13:04:06 +0100 Subject: [PATCH 3/5] Improve error handling All of these errors can only be the result of `Evaluator` having been dropped. Just ending the thread is more appropriate than panicking. --- crates/fj-host/src/evaluator.rs | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/crates/fj-host/src/evaluator.rs b/crates/fj-host/src/evaluator.rs index 00a1f96fb..eb84b0c15 100644 --- a/crates/fj-host/src/evaluator.rs +++ b/crates/fj-host/src/evaluator.rs @@ -1,6 +1,6 @@ use std::thread; -use crossbeam_channel::{Receiver, Sender}; +use crossbeam_channel::{Receiver, SendError, Sender}; use crate::{Error, Evaluation, Model}; @@ -18,23 +18,29 @@ impl Evaluator { thread::spawn(move || { while let Ok(TriggerEvaluation) = trigger_rx.recv() { - event_tx - .send(ModelEvent::ChangeDetected) - .expect("Expected channel to never disconnect"); + if let Err(SendError(_)) = + event_tx.send(ModelEvent::ChangeDetected) + { + break; + } let evaluation = match model.evaluate() { Ok(evaluation) => evaluation, Err(err) => { - event_tx - .send(ModelEvent::Error(err)) - .expect("Expected channel to never disconnect"); + if let Err(SendError(_)) = + event_tx.send(ModelEvent::Error(err)) + { + break; + } continue; } }; - event_tx - .send(ModelEvent::Evaluation(evaluation)) - .expect("Expected channel to never disconnect"); + if let Err(SendError(_)) = + event_tx.send(ModelEvent::Evaluation(evaluation)) + { + break; + }; } // The channel is disconnected, which means this instance of From 2e80653a35ba74e05fb4eefc5d7f4ab29a812e7b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 2 Nov 2022 13:05:53 +0100 Subject: [PATCH 4/5] Simplify status message With the time being displayed, showing the compile time is no longer as necessary. This change also makes some upcoming changes easier. --- crates/fj-window/src/run.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/crates/fj-window/src/run.rs b/crates/fj-window/src/run.rs index 0c5587785..4b52ee5c7 100644 --- a/crates/fj-window/src/run.rs +++ b/crates/fj-window/src/run.rs @@ -75,10 +75,7 @@ pub fn run( ); } ModelEvent::Evaluation(evaluation) => { - status.update_status(&format!( - "Model compiled successfully in {}!", - evaluation.compile_time - )); + status.update_status("Model compiled. Processing..."); match shape_processor.process(&evaluation.shape) { Ok(shape) => { From 332cc3ddbe210c3323fe7bac1cf4822476893a7e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 2 Nov 2022 13:09:44 +0100 Subject: [PATCH 5/5] Add additional status message This exposes that the model processing is blocking the event loop. The "processing..." and "processed." messages have different time stamps, but show up at the same time. --- crates/fj-window/src/run.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/fj-window/src/run.rs b/crates/fj-window/src/run.rs index 4b52ee5c7..0e6a73f12 100644 --- a/crates/fj-window/src/run.rs +++ b/crates/fj-window/src/run.rs @@ -97,6 +97,8 @@ pub fn run( } } } + + status.update_status("Model processed."); } ModelEvent::Error(err) => {