From dcbdc2a2c2acee0533108692d20457ac463aacc3 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Wed, 17 Nov 2021 23:08:46 -0500 Subject: redraw the clock every second --- src/main.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/main.rs b/src/main.rs index 3953bd5..b3852cd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -71,6 +71,27 @@ async fn async_main() -> anyhow::Result<()> { }); } + // redraw the clock every second + { + let action_w = action_w.clone(); + async_std::task::spawn(async move { + let first_sleep = 1_000_000_000_u64.saturating_sub( + chrono::Local::now().timestamp_subsec_nanos().into(), + ); + async_std::task::sleep(std::time::Duration::from_nanos( + first_sleep, + )) + .await; + let mut interval = async_std::stream::interval( + std::time::Duration::from_secs(1), + ); + action_w.send(crate::action::Action::Render).await.unwrap(); + while interval.next().await.is_some() { + action_w.send(crate::action::Action::Render).await.unwrap(); + } + }); + } + let debouncer = crate::action::debounce(action_r); while let Some(action) = debouncer.recv().await { state -- cgit v1.2.3