generated from GarandPLG/rust-flake-template
7541db79d8
App now receives an AppChannels struct; AppEvent enum removed. Event handling, tick generation, and audio communication are now performed through dedicated channels.
20 lines
444 B
Rust
20 lines
444 B
Rust
use std::{
|
|
sync::mpsc::Sender,
|
|
thread,
|
|
time::{Duration, Instant},
|
|
};
|
|
|
|
pub fn handle_tick_event(tx: Sender<()>, interval_ms: u8) {
|
|
let interval: Duration = Duration::from_millis(interval_ms as u64);
|
|
loop {
|
|
if tx.send(()).is_err() {
|
|
break;
|
|
}
|
|
|
|
let elapsed: Duration = Instant::now().elapsed();
|
|
if interval > elapsed {
|
|
thread::sleep(interval - elapsed);
|
|
}
|
|
}
|
|
}
|