From 5d8c9cd792e90b710456f8792c75e52740e3eaa1 Mon Sep 17 00:00:00 2001 From: Luuk van Oijen Date: Fri, 10 Nov 2023 10:04:56 +0100 Subject: [PATCH] interval introduced to avoid massive cpu usage --- src/main.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main.rs b/src/main.rs index 7783115..907f2fc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,9 +39,15 @@ async fn main() { .await .map_err(|e| error!("{:?}", e)) .expect("Failed to start server!"); + + // TODO: It'd be nicer if we didn't have to rely on this interval to limit the amount of times + // the loop can run per second. It'd be much better if it idled until one of the connections + // had a packet ready. + let mut interval = tokio::time::interval(tokio::time::Duration::from_nanos(1000)); // 5 ms = max 200 ticks per second loop { if let Err(e) = server.process().await { error!("{:?}", e); } + interval.tick().await; } }