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);
|
let notify_cloned: Arc<Notify> = Arc::clone(¬ify);
|
||||||
|
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
sleep(Duration::from_secs(3)).await;
|
|
||||||
|
|
||||||
let battery_charging = battery_2.time_to_empty().is_none();
|
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 {
|
if battery_2.state_of_charge().value == 1.0 && connection_type != Connection::None {
|
||||||
notify_cloned.notify_one();
|
sleep(Duration::from_secs(20)).await;
|
||||||
println!("battery notif");
|
} else {
|
||||||
continue
|
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();
|
networks_2.refresh_list();
|
||||||
if connection_type != get_connection(&networks_2) {
|
if connection_type != get_connection(&networks_2) {
|
||||||
notify_cloned.notify_one();
|
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()));
|
let sleep_or_notify = sleep(Duration::from_secs((60 - Local::now().second()).into()));
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
_ = sleep_or_notify => {
|
_ = sleep_or_notify => {}
|
||||||
println!("60 seconds elapsed");
|
_ = notify.notified() => {}
|
||||||
}
|
|
||||||
_ = notify.notified() => {
|
|
||||||
println!("waking up early");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue