Refactor examples :)
Vladimir Bauer
8 years ago
| 38 | 38 |
defer wg.Done()
|
| 39 | 39 |
max := 200 * time.Millisecond
|
| 40 | 40 |
for i := 0; i < total; i++ {
|
| 41 | |
time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
|
| 42 | |
b.Increment()
|
| 43 | 41 |
if b.ID() == 1 && i == 42 {
|
| 44 | 42 |
b.Complete()
|
| 45 | 43 |
return
|
| 46 | 44 |
}
|
|
45 |
time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
|
|
46 |
b.Increment()
|
| 47 | 47 |
}
|
| 48 | 48 |
}()
|
| 49 | 49 |
}
|
| 20 | 20 |
name := fmt.Sprintf("b#%02d:", i)
|
| 21 | 21 |
bar := p.AddBar(100, mpb.BarID(i), mpb.PrependDecorators(
|
| 22 | 22 |
func(s *decor.Statistics, _ chan<- int, _ <-chan int) string {
|
| 23 | |
if s.ID == 2 && s.Current == 42 {
|
|
23 |
// s.Current == 42 may never happen, if sleep btw increments is
|
|
24 |
// too short, thus using s.Current >= 42
|
|
25 |
if s.ID == 1 && s.Current >= 42 {
|
| 24 | 26 |
panic(wantPanic)
|
| 25 | 27 |
}
|
| 26 | 28 |
return name
|
|
| 30 | 32 |
go func() {
|
| 31 | 33 |
defer wg.Done()
|
| 32 | 34 |
for i := 0; i < 100; i++ {
|
| 33 | |
time.Sleep(10 * time.Millisecond)
|
|
35 |
time.Sleep(50 * time.Millisecond)
|
| 34 | 36 |
bar.Increment()
|
| 35 | 37 |
}
|
| 36 | 38 |
}()
|
| 38 | 38 |
defer wg.Done()
|
| 39 | 39 |
max := 200 * time.Millisecond
|
| 40 | 40 |
for i := 0; i < total; i++ {
|
| 41 | |
time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
|
| 42 | |
b.Increment()
|
| 43 | 41 |
if b.ID() == 1 && i == 42 {
|
| 44 | 42 |
p.RemoveBar(b)
|
| 45 | 43 |
return
|
| 46 | 44 |
}
|
|
45 |
time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
|
|
46 |
b.Increment()
|
| 47 | 47 |
}
|
| 48 | 48 |
}()
|
| 49 | 49 |
}
|