use std::time::Duration;
use kanal::{Receiver, bounded};
use sysinfo::Components;
const INTERVAL: Duration = Duration::from_secs(1);
pub(crate) fn start_thread() -> Receiver<Option<f32>> {
let (sender, receiver) = bounded(1);
std::thread::Builder::new()
.name("gled:temperature".to_owned())
.spawn(move || {
#[cfg(feature = "profiling")]
profiling::register_thread!("temperature");
loop {
let hottest = Components::new_with_refreshed_list()
.iter()
.filter_map(|component| component.temperature())
.filter(|temperature| temperature.is_finite())
.reduce(f32::max);
if sender.send(hottest).is_err() {
tracing::debug!("the engine is gone, stopping to read the temperature");
return;
}
std::thread::sleep(INTERVAL);
}
})
.expect("Could not spawn temperature thread");
receiver
}