From 01d58f30034b49afb8140bb4aa29c78e8301143f Mon Sep 17 00:00:00 2001 From: Marc Schoolderman Date: Fri, 22 Dec 2023 16:32:00 +0100 Subject: [PATCH] make code more readable --- ntpd/src/daemon/spawn/mod.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/ntpd/src/daemon/spawn/mod.rs b/ntpd/src/daemon/spawn/mod.rs index 6a69d8465..ffbb26687 100644 --- a/ntpd/src/daemon/spawn/mod.rs +++ b/ntpd/src/daemon/spawn/mod.rs @@ -79,6 +79,7 @@ impl SpawnEvent { pub enum SystemEvent { PeerRemoved(PeerRemovedEvent), PeerRegistered(PeerCreateParameters), + Idle, } impl SystemEvent { @@ -271,18 +272,14 @@ where action_tx: mpsc::Sender, mut system_notify: mpsc::Receiver, ) -> Result<(), E> { + use tokio::time::{timeout, Duration}; // basic event loop where init is called on startup and then wait for // events from the system before doing anything self.handle_init(&action_tx).await?; - while let Some(event) = { - use tokio::time::{timeout, Duration}; - loop { - if let Ok(result) = timeout(Duration::from_secs(60), system_notify.recv()).await { - break result; - } - self.handle_idle(&action_tx).await?; - } - } { + while let Some(event) = timeout(Duration::from_secs(60), system_notify.recv()) + .await + .unwrap_or(Some(SystemEvent::Idle)) + { match event { SystemEvent::PeerRegistered(peer_params) => { self.handle_registered(peer_params, &action_tx).await?; @@ -290,6 +287,9 @@ where SystemEvent::PeerRemoved(removed_peer) => { self.handle_peer_removed(removed_peer, &action_tx).await?; } + SystemEvent::Idle => { + self.handle_idle(&action_tx).await?; + } } }