refactor: use check_sub for sleep calculations
This commit is contained in:
@@ -416,9 +416,10 @@ impl DockerData {
|
|||||||
let mut now = std::time::Instant::now();
|
let mut now = std::time::Instant::now();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
loop {
|
loop {
|
||||||
let to_sleep = update_duration.saturating_sub(now.elapsed());
|
|
||||||
tokio::time::sleep(to_sleep).await;
|
|
||||||
docker_tx.send(DockerMessage::Update).await.ok();
|
docker_tx.send(DockerMessage::Update).await.ok();
|
||||||
|
if let Some(to_sleep) = update_duration.checked_sub(now.elapsed()) {
|
||||||
|
tokio::time::sleep(to_sleep).await;
|
||||||
|
}
|
||||||
now = std::time::Instant::now();
|
now = std::time::Instant::now();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
+8
-4
@@ -124,6 +124,7 @@ async fn main() {
|
|||||||
Ui::create(app_data, gui_state, input_tx, is_running).await;
|
Ui::create(app_data, gui_state, input_tx, is_running).await;
|
||||||
} else {
|
} else {
|
||||||
info!("in debug mode\n");
|
info!("in debug mode\n");
|
||||||
|
let mut now = std::time::Instant::now();
|
||||||
// Debug mode for testing, less pointless now, will display some basic information
|
// Debug mode for testing, less pointless now, will display some basic information
|
||||||
while is_running.load(Ordering::SeqCst) {
|
while is_running.load(Ordering::SeqCst) {
|
||||||
let err = app_data.lock().get_error();
|
let err = app_data.lock().get_error();
|
||||||
@@ -131,10 +132,12 @@ async fn main() {
|
|||||||
error!("{}", err);
|
error!("{}", err);
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
tokio::time::sleep(std::time::Duration::from_millis(u64::from(
|
if let Some(Ok(to_sleep)) = u128::from(args.docker_interval)
|
||||||
args.docker_interval,
|
.checked_sub(now.elapsed().as_millis())
|
||||||
)))
|
.map(u64::try_from)
|
||||||
.await;
|
{
|
||||||
|
tokio::time::sleep(std::time::Duration::from_millis(to_sleep)).await;
|
||||||
|
}
|
||||||
let containers = app_data
|
let containers = app_data
|
||||||
.lock()
|
.lock()
|
||||||
.get_container_items()
|
.get_container_items()
|
||||||
@@ -148,6 +151,7 @@ async fn main() {
|
|||||||
}
|
}
|
||||||
println!();
|
println!();
|
||||||
}
|
}
|
||||||
|
now = std::time::Instant::now();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user