Set settings twice when dirty, to be extra sure settings are set when set and not unset when set set set set

This commit is contained in:
NGnius (Graham) 2023-01-29 12:00:08 -05:00
parent f4e94d9e7d
commit 11c1fc0ddc
2 changed files with 9 additions and 5 deletions

View file

@ -218,12 +218,14 @@ pub struct ApiMessageHandler {
impl ApiMessageHandler {
pub fn process_forever(&mut self, settings: &mut Settings) {
let mut dirty_echo = true; // set everything twice, to make sure PowerTools wins on race conditions
while let Ok(msg) = self.intake.recv() {
let mut dirty = self.process(settings, msg);
while let Ok(msg) = self.intake.try_recv() {
dirty |= self.process(settings, msg);
}
if dirty {
if dirty || dirty_echo {
dirty_echo = dirty; // echo only once
// run on_set
if let Err(e) = settings.on_set() {
log::error!("Settings on_set() err: {}", e);

View file

@ -69,10 +69,6 @@ fn main() -> Result<(), ()> {
//let (_save_handle, save_sender) = save_worker::spawn(loaded_settings.clone());
let _resume_handle = resume_worker::spawn(api_sender.clone());
if let Err(e) = loaded_settings.on_set() {
log::error!("Startup Settings.on_set() error: {}", e);
}
let instance = Instance::new(PORT)
.register("V_INFO", |_: Vec<Primitive>| {
vec![format!("{} v{}", PACKAGE_NAME, PACKAGE_VERSION).into()]
@ -225,6 +221,12 @@ fn main() -> Result<(), ()> {
)
.register("GENERAL_idk", api::general::gunter);
if let Err(e) = loaded_settings.on_set() {
log::error!("Startup Settings.on_set() error: {}", e);
} else {
log::info!("Startup Settings.on_set() success");
}
api_worker::spawn(loaded_settings, api_handler);
instance