From 9d7f3cb80855374b5bee1b1172eb8d039e76bba2 Mon Sep 17 00:00:00 2001 From: Bartosz Nowak Date: Sun, 14 Apr 2024 14:00:44 +0200 Subject: [PATCH] handling termination --- crates/delegator/src/main.rs | 5 ++++- crates/executor/src/main.rs | 5 ++++- crates/peer/src/swarm.rs | 7 ++++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/crates/delegator/src/main.rs b/crates/delegator/src/main.rs index d3618a8..dc14300 100644 --- a/crates/delegator/src/main.rs +++ b/crates/delegator/src/main.rs @@ -18,7 +18,7 @@ async fn main() -> Result<(), Box> { // 2. Generate topic let topic = gossipsub_ident_topic(Network::Sepolia, Topic::NewJob); - let swarm_runner = SwarmRunner::new(&p2p_local_keypair, &topic)?; + let mut swarm_runner = SwarmRunner::new(&p2p_local_keypair, &topic)?; let mut registry_handler = RegistryHandler::new( "https://starknet-sepolia.public.blastapi.io", "0xcdd51fbc4e008f4ef807eaf26f5043521ef5931bbb1e04032a25bd845d286b", @@ -36,6 +36,9 @@ async fn main() -> Result<(), Box> { Some(Ok(event_vec)) = event_stream.next() => { debug!("{:?}", event_vec); }, + else => break } } + + Ok(()) } diff --git a/crates/executor/src/main.rs b/crates/executor/src/main.rs index 54d20df..2709a79 100644 --- a/crates/executor/src/main.rs +++ b/crates/executor/src/main.rs @@ -18,7 +18,7 @@ async fn main() -> Result<(), Box> { // 2. Generate topic let topic = gossipsub_ident_topic(Network::Sepolia, Topic::PickedJob); - let swarm_runner = SwarmRunner::new(&p2p_local_keypair, &topic)?; + let mut swarm_runner = SwarmRunner::new(&p2p_local_keypair, &topic)?; let mut registry_handler = RegistryHandler::new( "https://starknet-sepolia.public.blastapi.io", "0xcdd51fbc4e008f4ef807eaf26f5043521ef5931bbb1e04032a25bd845d286b", @@ -36,6 +36,9 @@ async fn main() -> Result<(), Box> { Some(Ok(event_vec)) = event_stream.next() => { debug!("{:?}", event_vec); }, + else => break } } + + Ok(()) } diff --git a/crates/peer/src/swarm.rs b/crates/peer/src/swarm.rs index 6947872..78d9c3e 100644 --- a/crates/peer/src/swarm.rs +++ b/crates/peer/src/swarm.rs @@ -66,10 +66,10 @@ impl SwarmRunner { } pub fn run( - mut self, + &mut self, send_topic: IdentTopic, mut send_topic_rx: mpsc::Receiver>, - ) -> Pin>> { + ) -> Pin + '_>> { let stream = stream! { loop { tokio::select! { @@ -105,7 +105,8 @@ impl SwarmRunner { debug!("Local node is listening on {address}"); } _ => {} - } + }, + else => break } } };