From 2381a64b71edb87fe5dee47a1bc03f081411c713 Mon Sep 17 00:00:00 2001 From: Luke Date: Fri, 8 May 2020 21:36:56 +1200 Subject: [PATCH] Use tokio to delay main loop, not thread::sleep --- CHANGELOG.md | 1 + rog-core/src/daemon.rs | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ba0df49..8e1c585c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 and even out. Previously the bottom rows were always last to be written. - Add more examples: ball, comet, pulser. - Refine the keyboard layout grid for GX502. +- Use tokio to delay main loop, not thread::sleep ## [0.9.4] - 2020-05-05 ### Changed diff --git a/rog-core/src/daemon.rs b/rog-core/src/daemon.rs index c66f6e72..a176c5c7 100644 --- a/rog-core/src/daemon.rs +++ b/rog-core/src/daemon.rs @@ -175,11 +175,11 @@ pub async fn start_daemon() -> Result<(), Box> { // Cool-down steps // This block is to prevent the loop spooling as fast as possible and saturating the CPU if now.duration_since(time_mark).as_millis() > 500 { - std::thread::sleep(Duration::from_millis(200)); + tokio::time::delay_for(Duration::from_millis(200)).await; } else if now.duration_since(time_mark).as_millis() > 100 { - std::thread::sleep(Duration::from_millis(50)); + tokio::time::delay_for(Duration::from_millis(50)).await; } else { - std::thread::sleep(Duration::from_micros(300)); + tokio::time::delay_for(Duration::from_micros(300)).await; } } });