Move tick to beginning of loop
The first tick completes immediately. Before this change messages would be sent twice at first.
This commit is contained in:
parent
92a611581f
commit
ca44c81e73
|
@ -19,6 +19,8 @@ pub async fn battery(config: BatteryConfig, output: OutputChannel) -> eyre::Resu
|
|||
|
||||
let mut interval = tokio::time::interval(config.update);
|
||||
loop {
|
||||
interval.tick().await;
|
||||
|
||||
let charge_now = async {
|
||||
let mut raw = String::new();
|
||||
File::open(&now_path)
|
||||
|
@ -56,7 +58,5 @@ pub async fn battery(config: BatteryConfig, output: OutputChannel) -> eyre::Resu
|
|||
..Default::default()
|
||||
})
|
||||
.await?;
|
||||
|
||||
interval.tick().await;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@ pub async fn hostname(
|
|||
);
|
||||
let mut interval = tokio::time::interval(config.update);
|
||||
loop {
|
||||
interval.tick().await;
|
||||
|
||||
let reply = proxy.hostname();
|
||||
let hostname: String = reply.await?;
|
||||
output
|
||||
|
@ -28,7 +30,5 @@ pub async fn hostname(
|
|||
..Default::default()
|
||||
})
|
||||
.await?;
|
||||
|
||||
interval.tick().await;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,8 @@ pub async fn iwd(
|
|||
|
||||
let mut interval = tokio::time::interval(config.update);
|
||||
loop {
|
||||
interval.tick().await;
|
||||
|
||||
let managed_objects = root_proxy.get_managed_objects().await?;
|
||||
let interface_path = get_interface_path(&managed_objects, &config.interface)
|
||||
.ok_or_eyre("Couldn't find interface")?;
|
||||
|
@ -64,7 +66,5 @@ pub async fn iwd(
|
|||
..Default::default()
|
||||
})
|
||||
.await?;
|
||||
|
||||
interval.tick().await;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@ use tokio::io::AsyncReadExt;
|
|||
pub async fn load(config: LoadConfig, output: OutputChannel) -> eyre::Result<()> {
|
||||
let mut interval = tokio::time::interval(config.update);
|
||||
loop {
|
||||
interval.tick().await;
|
||||
|
||||
let mut raw = String::new();
|
||||
let mut file = File::open("/proc/loadavg").await?;
|
||||
file.read_to_string(&mut raw).await?;
|
||||
|
@ -18,7 +20,5 @@ pub async fn load(config: LoadConfig, output: OutputChannel) -> eyre::Result<()>
|
|||
..Default::default()
|
||||
})
|
||||
.await?;
|
||||
|
||||
interval.tick().await;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,10 +38,12 @@ async fn find_time_zone(config: LocalTimeConfig, sender: watch::Sender<State>) -
|
|||
.build()
|
||||
.unwrap();
|
||||
|
||||
let mut interval = tokio::time::interval(config.update_interval);
|
||||
let mut prev_addr = None;
|
||||
|
||||
let mut interval = tokio::time::interval(config.update_interval);
|
||||
loop {
|
||||
interval.tick().await;
|
||||
|
||||
let curr_addr = if let Ok(curr_ipv6) = local_ip_address::local_ipv6() {
|
||||
Some(curr_ipv6)
|
||||
} else {
|
||||
|
@ -61,8 +63,6 @@ async fn find_time_zone(config: LocalTimeConfig, sender: watch::Sender<State>) -
|
|||
prev_addr = curr_addr;
|
||||
}
|
||||
}
|
||||
|
||||
interval.tick().await;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,8 @@ fn extract_value(line: &str) -> eyre::Result<u64> {
|
|||
pub async fn memory(config: MemoryConfig, output: OutputChannel) -> eyre::Result<()> {
|
||||
let mut interval = tokio::time::interval(config.update);
|
||||
loop {
|
||||
interval.tick().await;
|
||||
|
||||
let mut raw = [0u8; 256];
|
||||
let mut file = File::open("/proc/meminfo").await?;
|
||||
file.read_exact(&mut raw).await?;
|
||||
|
@ -58,7 +60,5 @@ pub async fn memory(config: MemoryConfig, output: OutputChannel) -> eyre::Result
|
|||
..Default::default()
|
||||
})
|
||||
.await?;
|
||||
|
||||
interval.tick().await;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue