diff --git a/src/fetcher.rs b/src/fetcher.rs index 86f2d0cc..c1a2d614 100644 --- a/src/fetcher.rs +++ b/src/fetcher.rs @@ -105,7 +105,12 @@ impl Fetcher { // We can't fetch as we are not async and we don't want to block the caller. // So we save this request as pending, and ask the syncer to sync us. self.pending.write().unwrap().insert(url); - let _ = GLOBALS.to_syncer.send("sync_fetcher".to_owned()); + tokio::spawn(async move { + if let Err(e) = GLOBALS.fetcher.sync().await { + tracing::error!("Problem fetching from web: {}", e); + } + }); + Ok(None) } diff --git a/src/globals.rs b/src/globals.rs index ed7c059f..9307a5c9 100644 --- a/src/globals.rs +++ b/src/globals.rs @@ -32,14 +32,6 @@ pub struct Globals { /// and stolen away when the Overlord is created. pub tmp_overlord_receiver: Mutex>>, - /// This is an mpsc channel. The Syncer listens on it. - /// To create a sender, just clone() it. - pub to_syncer: mpsc::UnboundedSender, - - /// This is ephemeral. It is filled during lazy_static initializtion, - /// and stolen away when the Syncer is created. - pub tmp_syncer_receiver: Mutex>>, - /// All nostr events, keyed by the event Id pub events: RwLock>, @@ -95,16 +87,11 @@ lazy_static! { // Setup a communications channel from the Minions to the Overlord. let (to_overlord, tmp_overlord_receiver) = mpsc::unbounded_channel(); - // Setup a communications channel from the UI (or anybody else) to the Syncer. - let (to_syncer, tmp_syncer_receiver) = mpsc::unbounded_channel(); - Globals { db: Mutex::new(None), to_minions, to_overlord, tmp_overlord_receiver: Mutex::new(Some(tmp_overlord_receiver)), - to_syncer, - tmp_syncer_receiver: Mutex::new(Some(tmp_syncer_receiver)), events: RwLock::new(HashMap::new()), incoming_events: RwLock::new(Vec::new()), relationships: RwLock::new(HashMap::new()), diff --git a/src/main.rs b/src/main.rs index a9c5f967..caec20bb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,7 +17,6 @@ mod process; mod relationship; mod settings; mod signer; -mod syncer; mod ui; use crate::comms::BusMessage; @@ -75,20 +74,6 @@ fn main() -> Result<(), Error> { } async fn tokio_main() { - // note: we don't get a spawn handle here, we don't signal this thread when we are exiting, - // we just let it die when tokio_main() exits. I think that is ok. - tokio::task::spawn(async move { - // Steal `tmp_syncer_receiver` from the GLOBALS, and give it to a new Syncer - let syncer_receiver = { - let mut mutex_option = GLOBALS.tmp_syncer_receiver.lock().await; - mem::replace(mutex_option.deref_mut(), None) - } - .unwrap(); - - let mut syncer = crate::syncer::Syncer::new(syncer_receiver); - syncer.run().await; - }); - // Steal `tmp_overlord_receiver` from the GLOBALS, and give it to a new Overlord let overlord_receiver = { let mut mutex_option = GLOBALS.tmp_overlord_receiver.lock().await; diff --git a/src/syncer.rs b/src/syncer.rs deleted file mode 100644 index e40894dd..00000000 --- a/src/syncer.rs +++ /dev/null @@ -1,35 +0,0 @@ -use crate::globals::GLOBALS; -use tokio::sync::mpsc; - -pub struct Syncer { - incoming: mpsc::UnboundedReceiver, -} - -impl Syncer { - pub fn new(incoming: mpsc::UnboundedReceiver) -> Syncer { - Syncer { incoming } - } - - pub async fn run(&mut self) { - loop { - let message = self.incoming.recv().await; - - if message.is_none() { - return; - } - - let message = message.unwrap(); - - match &*message { - "sync_fetcher" => { - if let Err(e) = GLOBALS.fetcher.sync().await { - tracing::error!("Problem fetching from web: {}", e); - } - } - _ => { - tracing::debug!("Syncer received unknown message: {}", message); - } - } - } - } -}