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

Improve status messages around model loading #1302

Merged
merged 5 commits into from
Nov 2, 2022
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
27 changes: 20 additions & 7 deletions crates/fj-host/src/evaluator.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::thread;

use crossbeam_channel::{Receiver, Sender};
use crossbeam_channel::{Receiver, SendError, Sender};

use crate::{Error, Evaluation, Model};

Expand All @@ -18,19 +18,29 @@ impl Evaluator {

thread::spawn(move || {
while let Ok(TriggerEvaluation) = trigger_rx.recv() {
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
Expand Down Expand Up @@ -60,6 +70,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),

Expand Down
2 changes: 1 addition & 1 deletion crates/fj-viewer/src/status_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
12 changes: 8 additions & 4 deletions crates/fj-window/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ 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 {}!",
evaluation.compile_time
));
status.update_status("Model compiled. Processing...");

match shape_processor.process(&evaluation.shape) {
Ok(shape) => {
Expand All @@ -95,6 +97,8 @@ pub fn run(
}
}
}

status.update_status("Model processed.");
}

ModelEvent::Error(err) => {
Expand Down