mirror of
https://github.com/hannobraun/Fornjot
synced 2025-02-28 01:55:52 +00:00
Move model loading into Watcher
This is slightly more complex, but makes it easier to trigger a model load from other sources than the watcher thread.
This commit is contained in:
parent
c2dbbf36c0
commit
3a35b4b803
@ -142,27 +142,13 @@ impl Model {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let shape = match self.load(¶meters) {
|
|
||||||
Ok(shape) => shape,
|
|
||||||
Err(Error::Compile) => {
|
|
||||||
// It would be better to display an error in the UI,
|
|
||||||
// where the user can actually see it. Issue:
|
|
||||||
// https://github.com/hannobraun/fornjot/issues/30
|
|
||||||
println!("Error compiling model");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
panic!("Error reloading model: {:?}", err);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// This will panic, if the other end is disconnected, which
|
// This will panic, if the other end is disconnected, which
|
||||||
// is probably the result of a panic on that thread, or the
|
// is probably the result of a panic on that thread, or the
|
||||||
// application is being shut down.
|
// application is being shut down.
|
||||||
//
|
//
|
||||||
// Either way, not much we can do about it here, except
|
// Either way, not much we can do about it here, except
|
||||||
// maybe to provide a better error message in the future.
|
// maybe to provide a better error message in the future.
|
||||||
tx.send(shape).unwrap();
|
tx.send(()).unwrap();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
@ -172,19 +158,39 @@ impl Model {
|
|||||||
Ok(Watcher {
|
Ok(Watcher {
|
||||||
_watcher: Box::new(watcher),
|
_watcher: Box::new(watcher),
|
||||||
channel: rx,
|
channel: rx,
|
||||||
|
model: self,
|
||||||
|
parameters,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Watcher {
|
pub struct Watcher {
|
||||||
_watcher: Box<dyn notify::Watcher>,
|
_watcher: Box<dyn notify::Watcher>,
|
||||||
channel: mpsc::Receiver<fj::Shape>,
|
channel: mpsc::Receiver<()>,
|
||||||
|
model: Model,
|
||||||
|
parameters: HashMap<String, String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Watcher {
|
impl Watcher {
|
||||||
pub fn receive(&self) -> Option<fj::Shape> {
|
pub fn receive(&self) -> Option<fj::Shape> {
|
||||||
match self.channel.try_recv() {
|
match self.channel.try_recv() {
|
||||||
Ok(shape) => Some(shape),
|
Ok(()) => {
|
||||||
|
let shape = match self.model.load(&self.parameters) {
|
||||||
|
Ok(shape) => shape,
|
||||||
|
Err(Error::Compile) => {
|
||||||
|
// It would be better to display an error in the UI,
|
||||||
|
// where the user can actually see it. Issue:
|
||||||
|
// https://github.com/hannobraun/fornjot/issues/30
|
||||||
|
println!("Error compiling model");
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
panic!("Error reloading model: {:?}", err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Some(shape)
|
||||||
|
}
|
||||||
Err(mpsc::TryRecvError::Empty) => {
|
Err(mpsc::TryRecvError::Empty) => {
|
||||||
// Nothing to receive from the channel.
|
// Nothing to receive from the channel.
|
||||||
None
|
None
|
||||||
|
Loading…
Reference in New Issue
Block a user