concurrent/
concurrent.rs

1use std::thread;
2use std::time::Duration;
3
4use avance::*;
5
6fn main() {
7    let total = 1000;
8    let mut v = vec![0; total];
9
10    let pb1 = AvanceBar::new(total as u64)
11        .with_style(Style::Balloon)
12        .with_desc("8 workers");
13    std::thread::scope(|t| {
14        for chunk in v.chunks_mut(total / 8) {
15            t.spawn(|| {
16                pb1.with_iter(chunk.iter()).for_each(|_| {
17                    thread::sleep(Duration::from_millis(3));
18                })
19            });
20        }
21    });
22    pb1.close();
23
24    std::thread::scope(|t| {
25        t.spawn(|| {
26            AvanceBar::with_config_of(&pb1)
27                .with_desc("1 worker")
28                .with_iter(v.iter_mut())
29                .for_each(|x| {
30                    thread::sleep(Duration::from_millis(3));
31                    *x = 2;
32                });
33        });
34    });
35}