conditional wait
This commit is contained in:
parent
9fffc90bce
commit
6fb8c64e64
26
src/main.rs
26
src/main.rs
|
@ -37,26 +37,26 @@ async fn main() {
|
||||||
let notify = Arc::new(Notify::new());
|
let notify = Arc::new(Notify::new());
|
||||||
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.state_of_charge().value == 1.0 && connection_type != Connection::None {
|
||||||
|
sleep(Duration::from_secs(20)).await;
|
||||||
|
} else {
|
||||||
|
sleep(Duration::from_secs(2)).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
if battery_2.time_to_empty().is_none() != battery_charging && battery_2.state_of_charge().value != 1.0 {
|
||||||
notify_cloned.notify_one();
|
notify_cloned.notify_one();
|
||||||
println!("battery notif");
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
let connection_type = get_connection(&networks_2);
|
|
||||||
|
|
||||||
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