conditional wait
This commit is contained in:
parent
9fffc90bce
commit
6fb8c64e64
28
src/main.rs
28
src/main.rs
|
@ -38,25 +38,25 @@ async fn main() {
|
|||
let notify_cloned: Arc<Notify> = Arc::clone(¬ify);
|
||||
|
||||
tokio::spawn(async move {
|
||||
|
||||
loop {
|
||||
sleep(Duration::from_secs(3)).await;
|
||||
|
||||
let battery_charging = battery_2.time_to_empty().is_none();
|
||||
battery_2.refresh().expect("could not refresh battery");
|
||||
let connection_type = get_connection(&networks_2);
|
||||
|
||||
if battery_2.time_to_empty().is_none() != battery_charging && battery_2.state_of_charge().value != 1.0 {
|
||||
notify_cloned.notify_one();
|
||||
println!("battery notif");
|
||||
continue
|
||||
if battery_2.state_of_charge().value == 1.0 && connection_type != Connection::None {
|
||||
sleep(Duration::from_secs(20)).await;
|
||||
} else {
|
||||
sleep(Duration::from_secs(2)).await;
|
||||
}
|
||||
|
||||
let connection_type = get_connection(&networks_2);
|
||||
battery_2.refresh().expect("could not refresh battery");
|
||||
if battery_2.time_to_empty().is_none() != battery_charging && battery_2.state_of_charge().value != 1.0 {
|
||||
notify_cloned.notify_one();
|
||||
continue
|
||||
}
|
||||
|
||||
networks_2.refresh_list();
|
||||
if connection_type != get_connection(&networks_2) {
|
||||
notify_cloned.notify_one();
|
||||
println!("network notif");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -80,12 +80,8 @@ async fn main() {
|
|||
|
||||
let sleep_or_notify = sleep(Duration::from_secs((60 - Local::now().second()).into()));
|
||||
tokio::select! {
|
||||
_ = sleep_or_notify => {
|
||||
println!("60 seconds elapsed");
|
||||
}
|
||||
_ = notify.notified() => {
|
||||
println!("waking up early");
|
||||
}
|
||||
_ = sleep_or_notify => {}
|
||||
_ = notify.notified() => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue