Skip to content

Commit

Permalink
Fixed progress bar not suspending multiprogress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
Vrajs16 authored and chris-laplante committed Jul 31, 2023
1 parent 505d282 commit bfc8bcb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/progress_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,8 @@ impl ProgressBar {
///
/// Useful for external code that writes to the standard output.
///
/// If the progress bar was added to a MultiProgress, it will suspend the entire MultiProgress
///
/// **Note:** The internal lock is held while `f` is executed. Other threads trying to print
/// anything on the progress bar will be blocked until `f` finishes.
/// Therefore, it is recommended to avoid long-running operations in `f`.
Expand Down
16 changes: 10 additions & 6 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,17 @@ impl BarState {
}

pub(crate) fn suspend<F: FnOnce() -> R, R>(&mut self, now: Instant, f: F) -> R {
if let Some(drawable) = self.draw_target.drawable(true, now) {
let _ = drawable.clear();
}
if let Some((state, _)) = self.draw_target.remote() {
state.write().unwrap().suspend(f, now)
} else {
if let Some(drawable) = self.draw_target.drawable(true, now) {
let _ = drawable.clear();
}

let ret = f();
let _ = self.draw(true, Instant::now());
ret
let ret = f();
let _ = self.draw(true, Instant::now());
ret
}
}

pub(crate) fn draw(&mut self, mut force_draw: bool, now: Instant) -> io::Result<()> {
Expand Down

0 comments on commit bfc8bcb

Please sign in to comment.