Skip to content

Commit bfc8bcb

Browse files
Vrajs16chris-laplante
authored andcommitted
Fixed progress bar not suspending multiprogress bar
1 parent 505d282 commit bfc8bcb

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/progress_bar.rs

+2
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,8 @@ impl ProgressBar {
391391
///
392392
/// Useful for external code that writes to the standard output.
393393
///
394+
/// If the progress bar was added to a MultiProgress, it will suspend the entire MultiProgress
395+
///
394396
/// **Note:** The internal lock is held while `f` is executed. Other threads trying to print
395397
/// anything on the progress bar will be blocked until `f` finishes.
396398
/// Therefore, it is recommended to avoid long-running operations in `f`.

src/state.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,17 @@ impl BarState {
161161
}
162162

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

168-
let ret = f();
169-
let _ = self.draw(true, Instant::now());
170-
ret
171+
let ret = f();
172+
let _ = self.draw(true, Instant::now());
173+
ret
174+
}
171175
}
172176

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

0 commit comments

Comments
 (0)