Codebase list golang-github-vbauerster-mpb / e70792d
Refactor examples :) Vladimir Bauer 8 years ago
3 changed file(s) with 8 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
3838 defer wg.Done()
3939 max := 200 * time.Millisecond
4040 for i := 0; i < total; i++ {
41 time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
42 b.Increment()
4341 if b.ID() == 1 && i == 42 {
4442 b.Complete()
4543 return
4644 }
45 time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
46 b.Increment()
4747 }
4848 }()
4949 }
2020 name := fmt.Sprintf("b#%02d:", i)
2121 bar := p.AddBar(100, mpb.BarID(i), mpb.PrependDecorators(
2222 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 {
2426 panic(wantPanic)
2527 }
2628 return name
3032 go func() {
3133 defer wg.Done()
3234 for i := 0; i < 100; i++ {
33 time.Sleep(10 * time.Millisecond)
35 time.Sleep(50 * time.Millisecond)
3436 bar.Increment()
3537 }
3638 }()
3838 defer wg.Done()
3939 max := 200 * time.Millisecond
4040 for i := 0; i < total; i++ {
41 time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
42 b.Increment()
4341 if b.ID() == 1 && i == 42 {
4442 p.RemoveBar(b)
4543 return
4644 }
45 time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
46 b.Increment()
4747 }
4848 }()
4949 }