From 51b5d6de71f96be264f2bc415522f1a4a1549fec Mon Sep 17 00:00:00 2001 From: Aleksei Voronov Date: Wed, 29 Nov 2023 11:24:55 +0100 Subject: [PATCH] Actually run all the components in parallel threads I have much to learn about async Rust, but the gist of it is that running try_join on a bunch of futures makes it run them in one task which is not at all what I want because all the components here are separate from each other. Apparently to make it spawn separate tasks, you need to use tokio::spawn. You live and learn. Ideally of course these should be separate processes entirely, but for now I'm far too lazy to deal with that --- src/main.rs | 8 ++++---- src/processes/post_indexer.rs | 2 +- src/processes/profile_classifier.rs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 66e8163..d96749e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -54,10 +54,10 @@ async fn main() -> Result<()> { info!("Starting everything up"); - tokio::try_join!( - post_indexer.start(), - profile_classifier.start(), - feed_server.serve(), + let _ = tokio::try_join!( + tokio::spawn(post_indexer.start()), + tokio::spawn(profile_classifier.start()), + tokio::spawn(feed_server.serve()), )?; Ok(()) diff --git a/src/processes/post_indexer.rs b/src/processes/post_indexer.rs index b55850d..547166d 100644 --- a/src/processes/post_indexer.rs +++ b/src/processes/post_indexer.rs @@ -34,7 +34,7 @@ impl PostIndexer { } impl PostIndexer { - pub async fn start(&self) -> Result<()> { + pub async fn start(self) -> Result<()> { info!("Starting"); loop { diff --git a/src/processes/profile_classifier.rs b/src/processes/profile_classifier.rs index 68db650..ac223ac 100644 --- a/src/processes/profile_classifier.rs +++ b/src/processes/profile_classifier.rs @@ -23,7 +23,7 @@ impl ProfileClassifier { } } - pub async fn start(&self) -> Result<()> { + pub async fn start(self) -> Result<()> { info!("Starting"); loop {