@@ -199,10 +199,3 @@ enum Route {
//
// }
// }
-
-fn main() {
- wasm_logger::init(wasm_logger::Config::default());
- log::debug!("App is starting");
- // yew::Renderer::::new().render();
- yew::Renderer::::new().render();
-}
diff --git a/axiom-profiler-GUI/src/results/mod.rs b/axiom-profiler-GUI/src/results/mod.rs
index ebaa6f27..9413e4e5 100644
--- a/axiom-profiler-GUI/src/results/mod.rs
+++ b/axiom-profiler-GUI/src/results/mod.rs
@@ -1,4 +1,5 @@
pub mod svg_result;
pub mod filters;
pub mod graph;
+pub mod worker;
diff --git a/axiom-profiler-GUI/src/results/svg_result.rs b/axiom-profiler-GUI/src/results/svg_result.rs
index f9c4232a..1ab218d7 100644
--- a/axiom-profiler-GUI/src/results/svg_result.rs
+++ b/axiom-profiler-GUI/src/results/svg_result.rs
@@ -1,8 +1,8 @@
use self::colors::HSVColour;
-use super::filters::{
+use super::{filters::{
filter_chain::{FilterChain, Msg as FilterChainMsg},
graph_filters::Filter,
-};
+}, worker::Worker};
use super::graph::graph_container::GraphContainer;
use material_yew::WeakComponentLink;
use num_format::{Locale, ToFormattedString};
@@ -33,6 +33,7 @@ pub enum Msg {
ApplyFilter(Filter),
ResetGraph,
GetUserPermission,
+ WorkerOutput(super::worker::WorkerOutput),
}
pub struct UserPermission {
@@ -59,6 +60,7 @@ pub struct SVGResult {
selected_insts: FxHashMap,
filter_chain_link: WeakComponentLink,
on_node_select: Callback,
+ worker: Option>>,
}
#[derive(Properties, PartialEq)]
@@ -83,11 +85,15 @@ impl Component for SVGResult {
selected_insts: FxHashMap::default(),
filter_chain_link: WeakComponentLink::default(),
on_node_select: ctx.link().callback(Msg::UpdateSelectedNodes),
+ worker: Some(Self::create_worker(ctx.link().clone())),
}
}
fn update(&mut self, ctx: &Context, msg: Self::Message) -> bool {
match msg {
+ Msg::WorkerOutput(out) => {
+ false
+ }
Msg::ApplyFilter(filter) => {
log::debug!("Applying filter {}", filter);
filter.apply(&mut self.inst_graph);
@@ -243,6 +249,30 @@ impl Component for SVGResult {
}
}
+impl SVGResult {
+ /// Deletes the old worker with its queue of messages and creates a new one.
+ /// Any enqueued work will still continue to run (there is no way to cancel this
+ /// at the moment, see https://github.com/rustwasm/gloo/issues/408) but will not
+ /// send a `WorkerOutput` message on completion.
+ pub fn reset_worker(&mut self, link: yew::html::Scope) {
+ // The old worker is dropped when overwritten here. Not sure we need the option?
+ self.worker = Some(Self::create_worker(link));
+ }
+ /// Sends an input to the worker to process.
+ pub fn send_worker_input(&mut self, input: super::worker::WorkerInput) {
+ self.worker.as_mut().unwrap().send(input);
+ }
+
+ /// Used internally.
+ fn create_worker(link: yew::html::Scope) -> Box> {
+ use yew_agent::Bridged;
+ let cb = std::rc::Rc::new(
+ move |e| link.send_message(Msg::WorkerOutput(e))
+ );
+ Worker::bridge(cb)
+ }
+}
+
struct QuantIdxToColourMap {
total_nr_of_quants: usize,
coprime: NonZeroUsize,
diff --git a/axiom-profiler-GUI/src/results/worker.rs b/axiom-profiler-GUI/src/results/worker.rs
new file mode 100644
index 00000000..71e17afe
--- /dev/null
+++ b/axiom-profiler-GUI/src/results/worker.rs
@@ -0,0 +1,59 @@
+use serde::{Deserialize, Serialize};
+use yew_agent::{HandlerId, Private, WorkerLink};
+
+pub struct Worker {
+ link: WorkerLink,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct WorkerInput {
+ pub n: u32,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct WorkerOutput {
+ pub input: u32,
+ pub value: u32,
+}
+
+impl yew_agent::Worker for Worker {
+ type Message = ();
+ type Input = WorkerInput;
+ type Output = WorkerOutput;
+ type Reach = Private;
+
+ fn create(link: WorkerLink) -> Self {
+ Self { link }
+ }
+
+ fn update(&mut self, _msg: Self::Message) {
+ // no messaging
+ }
+
+ fn handle_input(&mut self, msg: Self::Input, id: HandlerId) {
+ // this runs in a web worker
+ // and does not block the main
+ // browser thread!
+
+ let n = msg.n;
+
+ fn fib(n: u32) -> u32 {
+ if n <= 1 {
+ 1
+ } else {
+ fib(n - 1) + fib(n - 2)
+ }
+ }
+
+ let output = Self::Output { input: n, value: fib(n) };
+ self.link.respond(id, output);
+ }
+
+ fn name_of_resource() -> &'static str {
+ "worker.js"
+ }
+
+ fn resource_path_is_relative() -> bool {
+ true
+ }
+}
diff --git a/axiom-profiler-GUI/style.css b/axiom-profiler-GUI/style.css
index 7cf7be3c..0b84007a 100644
--- a/axiom-profiler-GUI/style.css
+++ b/axiom-profiler-GUI/style.css
@@ -11,10 +11,14 @@
flex: 1;
}
+.node {
+ cursor: pointer;
+}
+
.node:hover {
opacity: 0.6
}
.edge:hover * {
opacity: 0.4
-}
\ No newline at end of file
+}