--- a/src/greeter.rs +++ b/src/greeter.rs @@ -16,7 +16,7 @@ use tokio::{ process::Command, sync::{ oneshot::{Receiver, Sender}, - RwLock, RwLockWriteGuard, + Notify, RwLock, RwLockWriteGuard, }, }; use zeroize::Zeroize; @@ -90,6 +90,7 @@ pub struct Greeter { pub power_commands: HashMap, pub power_command: Option, + pub power_command_notify: Arc, pub power_setsid: bool, pub working: bool, --- a/src/main.rs +++ b/src/main.rs @@ -64,9 +64,12 @@ async fn run() -> Result<(), Box> { tokio::task::spawn({ let greeter = greeter.clone(); + let notify = greeter.read().await.power_command_notify.clone(); async move { loop { + notify.notified().await; + let command = greeter.write().await.power_command.take(); if let Some(mut command) = command { --- a/src/power.rs +++ b/src/power.rs @@ -50,4 +50,5 @@ pub fn power(greeter: &mut Greeter, option: PowerOption) { }; greeter.power_command = Some(command); + greeter.power_command_notify.notify_one(); }