generated from GarandPLG/rust-flake-template
Refactor App to use unified AppChannels for events
App now receives an AppChannels struct; AppEvent enum removed. Event handling, tick generation, and audio communication are now performed through dedicated channels.
This commit is contained in:
+11
-14
@@ -1,22 +1,19 @@
|
||||
use crate::app::threads::AppEvent;
|
||||
use std::{
|
||||
sync::mpsc::Sender,
|
||||
thread,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
pub fn spawn_tick_thread(tx: Sender<AppEvent>, interval_ms: u64) {
|
||||
thread::spawn(move || {
|
||||
let interval: Duration = Duration::from_millis(interval_ms);
|
||||
loop {
|
||||
if tx.send(AppEvent::Tick).is_err() {
|
||||
break;
|
||||
}
|
||||
|
||||
let elapsed: Duration = Instant::now().elapsed();
|
||||
if interval > elapsed {
|
||||
thread::sleep(interval - elapsed);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user