Use tokio to delay main loop, not thread::sleep

This commit is contained in:
Luke
2020-05-08 21:36:56 +12:00
parent e09dd345c0
commit 2381a64b71
2 changed files with 4 additions and 3 deletions

View File

@@ -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

View File

@@ -175,11 +175,11 @@ pub async fn start_daemon() -> Result<(), Box<dyn Error>> {
// 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;
}
}
});