Skip to content

Commit

Permalink
Tidying
Browse files Browse the repository at this point in the history
  • Loading branch information
huntc committed Sep 28, 2023
1 parent 6d5c7cd commit 8b50a2c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
20 changes: 12 additions & 8 deletions examples/iot-service/frontend/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct Props;

pub struct App {
entity_id: EntityId,
query: mpsc::Sender<EntityId>,
temperature_query: mpsc::Sender<EntityId>,
temperature: temperature::State,
}

Expand All @@ -25,7 +25,7 @@ pub enum Message {
entity_id: EntityId,
},
Submit,
Update {
UpdateTemperature {
envelope: EventEnvelope<temperature::Event>,
},
}
Expand All @@ -39,16 +39,20 @@ impl Component for App {
let (temperature_events, mut temperature_event_receiver) =
broadcast::channel(MAX_TEMPERATURE_EVENTS);

let (query, query_receiver) = mpsc::channel(MAX_TEMPERATURE_QUERIES);
let (temperature_query, temperature_query_receiver) =
mpsc::channel(MAX_TEMPERATURE_QUERIES);

platform::spawn_local(temperature::task(query_receiver, temperature_events));
platform::spawn_local(temperature::task(
temperature_query_receiver,
temperature_events,
));

let task_link = ctx.link().clone();
platform::spawn_local(async move {
loop {
let result = temperature_event_receiver.recv().await;
match result {
Ok(envelope) => task_link.send_message(Message::Update { envelope }),
Ok(envelope) => task_link.send_message(Message::UpdateTemperature { envelope }),
Err(broadcast::error::RecvError::Lagged(_)) => (),
Err(_) => break,
}
Expand All @@ -57,7 +61,7 @@ impl Component for App {

Self {
entity_id: EntityId::from(""),
query,
temperature_query,
temperature: temperature::State::default(),
}
}
Expand All @@ -72,7 +76,7 @@ impl Component for App {
Message::Submit => {
self.temperature = temperature::State::default();

let task_query = self.query.clone();
let task_query = self.temperature_query.clone();
let task_entity_id = self.entity_id.clone();
ctx.link().send_future_batch(async move {
let _ = task_query.send(task_entity_id).await;
Expand All @@ -82,7 +86,7 @@ impl Component for App {
true
}

Message::Update { envelope } => {
Message::UpdateTemperature { envelope } => {
if envelope.entity_id == self.entity_id {
temperature::Behavior::on_event(
&EntityContext {
Expand Down
2 changes: 1 addition & 1 deletion examples/iot-service/frontend/src/temperature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use tokio_stream::StreamExt;

pub use iot_service_model::temperature::{Behavior, Command, Event, SecretDataValue, State};

// Execute the entity manager for this entity
// Execute the event source query for commanded entity ids

pub async fn task(
mut query_receiver: mpsc::Receiver<EntityId>,
Expand Down

0 comments on commit 8b50a2c

Please sign in to comment.