Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Reiter committed Sep 28, 2024
1 parent 87e0880 commit 6e87c32
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
10 changes: 7 additions & 3 deletions wireman/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,19 @@ impl App {
resp.set(&mut self.ctx.messages.borrow_mut().response.editor);
self.ctx.messages.borrow_mut().handler.take();
}
InternalStreamData::Reflection(desc) => {
if let Ok(desc) = desc {
InternalStreamData::Reflection(desc) => match desc {
Ok(desc) => {
self.ctx
.selection
.borrow_mut()
.update_proto_descriptor(desc.clone());
self.ctx.selection.borrow_mut().selection_mode = SelectionMode::Reflection;
}
}
Err(err) => {
// TODO: Handle error
Logger::critical(err)
}
},
}
}

Expand Down
18 changes: 5 additions & 13 deletions wireman/src/model/reflection.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![allow(clippy::module_name_repetitions)]
use core::ProtoDescriptor;
use logger::Logger;
use std::cell::RefCell;
use std::rc::Rc;
use tokio::sync::mpsc::Sender;
Expand Down Expand Up @@ -40,27 +39,20 @@ impl ReflectionModel {
}

pub fn dispatch_reflection(&mut self) {
Logger::debug("boom toggle");
self.dispatch_reflection = true;
}

pub fn handle_reflection(&mut self, sx: Sender<InternalStreamData>) {
let host = self.headers.borrow().address();
self.dispatch_reflection = false;
tokio::spawn(async move {
Logger::debug("spawn");
match ProtoDescriptor::reflect(&host).await {
Ok(desc) => {
let _ = sx.send(InternalStreamData::Reflection(Ok(desc))).await;
}
let event = match ProtoDescriptor::reflect(&host).await {
Ok(desc) => InternalStreamData::Reflection(Ok(desc)),
Err(err) => {
let err_str = format!("Server reflection failed: {err}");
let _ = sx
.send(InternalStreamData::Reflection(Err(err_str.clone())))
.await;
Logger::critical(err_str)
InternalStreamData::Reflection(Err(format!("Server reflection failed: {err}")))
}
}
};
let _ = sx.send(event).await;
});
}
}

0 comments on commit 6e87c32

Please sign in to comment.