Skip to content

Commit

Permalink
Do not close backend thread prematurely, add shutdown signal
Browse files Browse the repository at this point in the history
  • Loading branch information
adzialocha committed Dec 8, 2024
1 parent 5db1001 commit 632cdea
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use p2panda_sync::log_sync::LogSyncProtocol;
use p2panda_sync::{TopicMap, TopicQuery};
use serde::{Deserialize, Serialize};
use tokio::runtime::Builder;
use tokio::sync::mpsc;
use tokio::sync::{mpsc, oneshot};

#[derive(Clone, Default, Debug, PartialEq, Eq, std::hash::Hash, Serialize, Deserialize)]
struct TextDocument([u8; 32]);
Expand Down Expand Up @@ -81,6 +81,7 @@ impl TopicMap<TextDocument, HashMap<PublicKey, Vec<LogId>>> for TextDocumentStor
pub fn run() -> Result<(mpsc::Sender<Vec<u8>>, mpsc::Receiver<Vec<u8>>)> {
let (to_network, mut from_app) = mpsc::channel::<Vec<u8>>(512);
let (to_app, from_network) = mpsc::channel(512);
let (shutdown_tx, shutdown_rx) = oneshot::channel::<()>();

let _rt_handle: JoinHandle<Result<()>> = std::thread::spawn(|| {
let runtime = Builder::new_current_thread()
Expand Down Expand Up @@ -145,6 +146,8 @@ pub fn run() -> Result<(mpsc::Sender<Vec<u8>>, mpsc::Receiver<Vec<u8>>)> {
}
});

shutdown_rx.await?;

Ok(())
})
});
Expand Down

0 comments on commit 632cdea

Please sign in to comment.