Move update_interval into IncrementableProgress

This commit is contained in:
RumovZ 2022-04-30 09:14:56 +02:00
parent b002c45848
commit 58235d3709

View file

@ -21,10 +21,9 @@ pub(crate) struct IncrementableProgress<P> {
progress_fn: Box<dyn FnMut(P, bool) -> bool>, progress_fn: Box<dyn FnMut(P, bool) -> bool>,
count_map: Option<Box<dyn FnMut(usize) -> P>>, count_map: Option<Box<dyn FnMut(usize) -> P>>,
count: usize, count: usize,
update_interval: usize,
} }
const UPDATE_INTERVAL: usize = 17;
impl<P> IncrementableProgress<P> { impl<P> IncrementableProgress<P> {
/// `progress_fn: (progress, throttle) -> should_continue` /// `progress_fn: (progress, throttle) -> should_continue`
pub(crate) fn new(progress_fn: impl 'static + FnMut(P, bool) -> bool) -> Self { pub(crate) fn new(progress_fn: impl 'static + FnMut(P, bool) -> bool) -> Self {
@ -32,6 +31,7 @@ impl<P> IncrementableProgress<P> {
progress_fn: Box::new(progress_fn), progress_fn: Box::new(progress_fn),
count_map: None, count_map: None,
count: 0, count: 0,
update_interval: 17,
} }
} }
@ -47,7 +47,7 @@ impl<P> IncrementableProgress<P> {
/// Must have called `set_count_map()` before calling this. /// Must have called `set_count_map()` before calling this.
pub(crate) fn increment(&mut self) -> Result<()> { pub(crate) fn increment(&mut self) -> Result<()> {
self.count += 1; self.count += 1;
if self.count % UPDATE_INTERVAL != 0 { if self.count % self.update_interval != 0 {
return Ok(()); return Ok(());
} }
let progress = self.mapped_progress()?; let progress = self.mapped_progress()?;