From 2dfeb29b752af33d33b04cc368b436410a7c0c3e Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Sun, 10 Jan 2021 23:29:24 +0200 Subject: [PATCH] jobs/Timer: add set_interval() --- src/components/utilities/widgets.rs | 6 ------ src/jobs.rs | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/components/utilities/widgets.rs b/src/components/utilities/widgets.rs index 5d01630e..361f0841 100644 --- a/src/components/utilities/widgets.rs +++ b/src/components/utilities/widgets.rs @@ -1343,12 +1343,6 @@ impl ProgressSpinner { } } -impl Drop for ProgressSpinner { - fn drop(&mut self) { - self.stop(); - } -} - impl fmt::Display for ProgressSpinner { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "progress bar") diff --git a/src/jobs.rs b/src/jobs.rs index 2ded0da4..261ec565 100644 --- a/src/jobs.rs +++ b/src/jobs.rs @@ -138,6 +138,16 @@ impl Timer { pub fn disable(&self) { self.job_executor.disable_timer(self.id); } + + pub fn set_interval(&self, new_val: Duration) { + self.job_executor.set_interval(self.id, new_val); + } +} + +impl Drop for Timer { + fn drop(&mut self) { + self.disable(); + } } impl JobExecutor { @@ -329,6 +339,13 @@ impl JobExecutor { timer.active = false; } } + + fn set_interval(&self, id: Uuid, new_val: Duration) { + let mut timers_lck = self.timers.lock().unwrap(); + if let Some(timer) = timers_lck.get_mut(&id) { + timer.interval = new_val; + } + } } pub type JobChannel = oneshot::Receiver;