Codebase list golang-github-vbauerster-mpb / 0b28369
Refactor: examples Vladimir Bauer 8 years ago
9 changed file(s) with 17 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
4343
4444 go func() {
4545 defer wg.Done()
46 max := 200 * time.Millisecond
4647 for !bar.Completed() {
47 time.Sleep(randomDuration(200 * time.Millisecond))
48 time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
4849 bar.Increment()
4950 }
5051 }()
5354 p.Stop()
5455 fmt.Println("stop")
5556 }
56
57 func randomDuration(max time.Duration) time.Duration {
58 return time.Duration(rand.Intn(10)+1) * max / 10
59 }
3636 )
3737 go func() {
3838 defer wg.Done()
39 max := 200 * time.Millisecond
3940 for i := 0; i < total; i++ {
40 time.Sleep(time.Duration(rand.Intn(10)+1) * (200 * time.Millisecond) / 10)
41 time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
4142 b.Increment()
4243 if b.ID() == 1 && i == 42 {
4344 b.Complete()
3939 bar.SetTotal(300, true)
4040 }()
4141
42 max := 200 * time.Millisecond
4243 for i := 0; i < 300; i++ {
4344 if i == 140 {
4445 close(totalUpd1)
4647 if i == 250 {
4748 close(totalUpd2)
4849 }
49 time.Sleep(time.Duration(rand.Intn(10)+1) * (200 * time.Millisecond) / 10)
50 time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
5051 bar.Increment()
5152 }
5253
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 if s.ID == 2 && s.Current == 42 {
2424 panic(wantPanic)
2525 }
2626 return name
3636 )
3737 go func() {
3838 defer wg.Done()
39 max := 200 * time.Millisecond
3940 for i := 0; i < total; i++ {
40 time.Sleep(time.Duration(rand.Intn(10)+1) * (200 * time.Millisecond) / 10)
41 time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
4142 b.Increment()
4243 }
4344 }()
3737 )
3838 go func() {
3939 defer wg.Done()
40 max := 200 * time.Millisecond
4041 for i := 0; i < total; i++ {
41 time.Sleep(time.Duration(rand.Intn(10)+1) * (200 * time.Millisecond) / 10)
42 time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
4243 b.Increment()
4344 }
4445 }()
3636 )
3737 go func() {
3838 defer wg.Done()
39 max := 200 * time.Millisecond
3940 for i := 0; i < total; i++ {
40 time.Sleep(time.Duration(rand.Intn(10)+1) * (200 * time.Millisecond) / 10)
41 time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
4142 b.Increment()
4243 if b.ID() == 1 && i == 42 {
4344 p.RemoveBar(b)
3636 )
3737 go func() {
3838 defer wg.Done()
39 max := 200 * time.Millisecond
3940 for i := 0; i < total; i++ {
40 time.Sleep(time.Duration(rand.Intn(10)+1) * (200 * time.Millisecond) / 10)
41 time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
4142 if i&1 == 1 {
4243 priority := total - int(b.Current())
4344 p.UpdateBarPriority(b, priority)
3838
3939 go func() {
4040 defer wg.Done()
41 max := 300 * time.Millisecond
4142 for i := 0; i < total; i++ {
42 time.Sleep(time.Duration(rand.Intn(10)+1) * (200 * time.Millisecond) / 10)
43 time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
4344 bar.Increment()
4445 }
4546 }()