jobs/Timer: add set_interval()

lazy_fetch
Manos Pitsidianakis 2021-01-10 23:29:24 +02:00
parent 63d2fb93f4
commit 2dfeb29b75
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
2 changed files with 17 additions and 6 deletions

View File

@ -1343,12 +1343,6 @@ impl ProgressSpinner {
} }
} }
impl Drop for ProgressSpinner {
fn drop(&mut self) {
self.stop();
}
}
impl fmt::Display for ProgressSpinner { impl fmt::Display for ProgressSpinner {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "progress bar") write!(f, "progress bar")

View File

@ -138,6 +138,16 @@ impl Timer {
pub fn disable(&self) { pub fn disable(&self) {
self.job_executor.disable_timer(self.id); 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 { impl JobExecutor {
@ -329,6 +339,13 @@ impl JobExecutor {
timer.active = false; 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<T> = oneshot::Receiver<T>; pub type JobChannel<T> = oneshot::Receiver<T>;