From fc39aea5820353e8ee82e8ed2dd12a088f8acfc2 Mon Sep 17 00:00:00 2001 From: Jack Wills <32690432+mrjackwills@users.noreply.github.com> Date: Mon, 30 May 2022 00:44:40 +0000 Subject: [PATCH] refactor: input m_button replace is_some() with a if let Some(), and improve comments --- src/input_handler/mod.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/input_handler/mod.rs b/src/input_handler/mod.rs index f0b90e8..5c1135e 100644 --- a/src/input_handler/mod.rs +++ b/src/input_handler/mod.rs @@ -101,9 +101,14 @@ impl InputHandler { let gui_state = Arc::clone(&self.gui_state); - if self.info_sleep.is_some() { - self.info_sleep.as_ref().unwrap().abort() + // If the info box sleep handle is currently being executed, as in m is pressed twice within a 4000ms window + // then cancel the first handle, as a new handle will be invoked + if let Some(info_sleep_timer) = self.info_sleep.as_ref() { + info_sleep_timer.abort(); } + + // Some(self.info_sleep).as_ref().unwrap().ab + self.info_sleep = Some(tokio::spawn(async move { tokio::time::sleep(std::time::Duration::from_millis(4000)).await; gui_state.lock().reset_info_box()