Skip to content

Commit

Permalink
Refreshing topics at 5 second intervals.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmackdev committed Sep 4, 2023
1 parent d022b71 commit 92f36c1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions pubsubman/src/actions.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
use std::time::Duration;

use pubsubman_backend::{
message::FrontendMessage,
model::{PubsubMessageToPublish, SubscriptionName, TopicName},
};
use tokio::sync::mpsc::Sender;
use tokio::{sync::mpsc::Sender, time::sleep};
use tokio_util::sync::CancellationToken;

pub fn refresh_topics(front_tx: &Sender<FrontendMessage>) {
pub fn refresh_topics(front_tx: &Sender<FrontendMessage>, delay_millis: Option<u64>) {
let front_tx = front_tx.to_owned();

tokio::spawn(async move {
if let Some(delay_millis) = delay_millis {
sleep(Duration::from_millis(delay_millis)).await;
}
let _ = front_tx.send(FrontendMessage::RefreshTopicsRequest).await;
});
}
Expand Down
4 changes: 2 additions & 2 deletions pubsubman/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl App {
Backend::new(back_tx, front_rx, emulator_project_id).init();
});

refresh_topics(&front_tx);
refresh_topics(&front_tx, None);

let memory = cc
.storage
Expand All @@ -69,7 +69,7 @@ impl App {
Ok(message) => match message {
BackendMessage::TopicsUpdated(topic_names) => {
self.topic_names = topic_names;
refresh_topics(&self.front_tx);
refresh_topics(&self.front_tx, Some(5000));
}
BackendMessage::SubscriptionCreated(topic_name, sub_name) => {
self.memory.subscriptions.insert(topic_name, sub_name);
Expand Down

0 comments on commit 92f36c1

Please sign in to comment.