Skip to content

Commit bb75686

Browse files
committed
Fix additional progress bar
This forces all meaningful work to be executed in rayon thread pool, so the main thread doesn't create its progress bar.
1 parent 9e9d5bb commit bb75686

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/main.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ static OVERALL_PROGRESS: LazyLock<ProgressBar> =
2424

2525
thread_local! {
2626
static LOCAL_PROGRESS: ProgressBar = {
27-
PROGRESS.insert_before(&OVERALL_PROGRESS, ProgressBar::new_spinner())
27+
if rayon::current_thread_index().is_some() {
28+
PROGRESS.insert_before(&OVERALL_PROGRESS, ProgressBar::new_spinner())
29+
} else {
30+
ProgressBar::hidden()
31+
}
2832
};
2933
}
3034

@@ -69,6 +73,11 @@ fn copy(path: &Path, file_type: FileType) -> std::io::Result<()> {
6973
fn main() {
7074
LazyLock::force(&OPTIONS);
7175

72-
let file_type = std::fs::metadata(&OPTIONS.src).unwrap().file_type();
73-
copy("".as_ref(), file_type).unwrap();
76+
rayon::scope(|s| {
77+
s.spawn(|_| {
78+
OVERALL_PROGRESS.inc_length(1);
79+
let file_type = std::fs::metadata(&OPTIONS.src).unwrap().file_type();
80+
copy("".as_ref(), file_type).unwrap();
81+
});
82+
});
7483
}

0 commit comments

Comments
 (0)