Skip to content

Commit 0434aa1

Browse files
committed
Use a single now time
1 parent ea215b4 commit 0434aa1

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

watchers/src/watchers/idle.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ impl State {
3838
seconds_since_input: u32,
3939
client: &Arc<ReportClient>,
4040
) -> anyhow::Result<()> {
41+
let now = Utc::now();
4142
let time_since_input = Duration::seconds(i64::from(seconds_since_input));
4243

43-
self.last_input_time = Utc::now() - time_since_input;
44+
self.last_input_time = now - time_since_input;
4445

4546
if self.is_idle
4647
&& u64::from(seconds_since_input) < self.idle_timeout.num_seconds().try_into().unwrap()
@@ -56,9 +57,7 @@ impl State {
5657
self.is_changed = true;
5758
}
5859

59-
self.send_ping(client).await?;
60-
61-
Ok(())
60+
self.send_ping(now, client).await
6261
}
6362

6463
pub async fn send_reactive(&mut self, client: &Arc<ReportClient>) -> anyhow::Result<()> {
@@ -67,12 +66,10 @@ impl State {
6766
self.last_input_time = now;
6867
}
6968

70-
self.send_ping(client).await
69+
self.send_ping(now, client).await
7170
}
7271

73-
async fn send_ping(&mut self, client: &Arc<ReportClient>) -> anyhow::Result<()> {
74-
let now = Utc::now();
75-
72+
async fn send_ping(&mut self, now: DateTime<Utc>, client: &Arc<ReportClient>) -> anyhow::Result<()> {
7673
if self.is_changed {
7774
let result = if self.is_idle {
7875
debug!("Reporting as changed to idle");

0 commit comments

Comments
 (0)