Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Remove MultiProgress::join() #231

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 24 additions & 19 deletions examples/finebars.rs
Expand Up @@ -15,24 +15,29 @@ fn main() {

let m = MultiProgress::new();

for s in styles.iter() {
let pb = m.add(ProgressBar::new(512));
pb.set_style(
ProgressStyle::default_bar()
.template(&format!("{{prefix:.bold}}▕{{bar:.{}}}▏{{msg}}", s.2))
.progress_chars(s.1),
);
pb.set_prefix(s.0);
let wait = Duration::from_millis(thread_rng().gen_range(10, 30));
thread::spawn(move || {
for i in 0..512 {
pb.inc(1);
pb.set_message(&format!("{:3}%", 100 * i / 512));
thread::sleep(wait);
}
pb.finish_with_message("100%");
});
}
let handles: Vec<_> = styles
.iter()
.map(|s| {
let pb = m.add(ProgressBar::new(512));
pb.set_style(
ProgressStyle::default_bar()
.template(&format!("{{prefix:.bold}}▕{{bar:.{}}}▏{{msg}}", s.2))
.progress_chars(s.1),
);
pb.set_prefix(s.0);
let wait = Duration::from_millis(thread_rng().gen_range(10, 30));
thread::spawn(move || {
for i in 0..512 {
pb.inc(1);
pb.set_message(&format!("{:3}%", 100 * i / 512));
thread::sleep(wait);
}
pb.finish_with_message("100%");
})
})
.collect();

m.join().unwrap();
for h in handles {
let _ = h.join();
}
}
5 changes: 2 additions & 3 deletions examples/morebars.rs
Expand Up @@ -27,7 +27,6 @@ fn main() {
pb.inc(1);
}
pb.finish_with_message("done");
});

m.join().unwrap();
})
.join();
}
5 changes: 2 additions & 3 deletions examples/multi-tree.rs
Expand Up @@ -108,9 +108,8 @@ fn main() {
}
thread::sleep(Duration::from_millis(15));
}
});

mp.join().unwrap();
})
.join();

println!("===============================");
println!("the tree should be the same as:");
Expand Down
8 changes: 5 additions & 3 deletions examples/multi.rs
Expand Up @@ -11,7 +11,7 @@ fn main() {

let pb = m.add(ProgressBar::new(128));
pb.set_style(sty.clone());
let _ = thread::spawn(move || {
let h1 = thread::spawn(move || {
for i in 0..128 {
pb.set_message(&format!("item #{}", i + 1));
pb.inc(1);
Expand All @@ -22,7 +22,7 @@ fn main() {

let pb = m.add(ProgressBar::new(128));
pb.set_style(sty.clone());
let _ = thread::spawn(move || {
let h2 = thread::spawn(move || {
for _ in 0..3 {
pb.set_position(0);
for i in 0..128 {
Expand All @@ -45,5 +45,7 @@ fn main() {
pb.finish_with_message("done");
});

m.join_and_clear().unwrap();
let _ = h1.join();
let _ = h2.join();
m.clear().unwrap();
}
39 changes: 22 additions & 17 deletions examples/yarnish.rs
Expand Up @@ -71,24 +71,29 @@ pub fn main() {
PAPER
);
let m = MultiProgress::new();
for i in 0..4 {
let count = rng.gen_range(30, 80);
let pb = m.add(ProgressBar::new(count));
pb.set_style(spinner_style.clone());
pb.set_prefix(&format!("[{}/?]", i + 1));
let _ = thread::spawn(move || {
let mut rng = rand::thread_rng();
let pkg = PACKAGES.choose(&mut rng).unwrap();
for _ in 0..count {
let cmd = COMMANDS.choose(&mut rng).unwrap();
pb.set_message(&format!("{}: {}", pkg, cmd));
pb.inc(1);
thread::sleep(Duration::from_millis(rng.gen_range(25, 200)));
}
pb.finish_with_message("waiting...");
});
let handles: Vec<_> = (0..4u32)
.map(|i| {
let count = rng.gen_range(30, 80);
let pb = m.add(ProgressBar::new(count));
pb.set_style(spinner_style.clone());
pb.set_prefix(&format!("[{}/?]", i + 1));
thread::spawn(move || {
let mut rng = rand::thread_rng();
let pkg = PACKAGES.choose(&mut rng).unwrap();
for _ in 0..count {
let cmd = COMMANDS.choose(&mut rng).unwrap();
pb.set_message(&format!("{}: {}", pkg, cmd));
pb.inc(1);
thread::sleep(Duration::from_millis(rng.gen_range(25, 200)));
}
pb.finish_with_message("waiting...");
})
})
.collect();
for h in handles {
let _ = h.join();
}
m.join_and_clear().unwrap();
m.clear().unwrap();

println!("{} Done in {}", SPARKLE, HumanDuration(started.elapsed()));
}