diff --git a/examples/cancel/main.go b/examples/cancel/main.go index b782a58..bdaf555 100644 --- a/examples/cancel/main.go +++ b/examples/cancel/main.go @@ -44,8 +44,9 @@ go func() { defer wg.Done() + max := 200 * time.Millisecond for !bar.Completed() { - time.Sleep(randomDuration(200 * time.Millisecond)) + time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10) bar.Increment() } }() @@ -54,7 +55,3 @@ p.Stop() fmt.Println("stop") } - -func randomDuration(max time.Duration) time.Duration { - return time.Duration(rand.Intn(10)+1) * max / 10 -} diff --git a/examples/complete/main.go b/examples/complete/main.go index 69733f8..887a004 100644 --- a/examples/complete/main.go +++ b/examples/complete/main.go @@ -37,8 +37,9 @@ ) go func() { defer wg.Done() + max := 200 * time.Millisecond for i := 0; i < total; i++ { - time.Sleep(time.Duration(rand.Intn(10)+1) * (200 * time.Millisecond) / 10) + time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10) b.Increment() if b.ID() == 1 && i == 42 { b.Complete() diff --git a/examples/dynTotal/main.go b/examples/dynTotal/main.go index d4e13b2..1df7c4a 100644 --- a/examples/dynTotal/main.go +++ b/examples/dynTotal/main.go @@ -40,6 +40,7 @@ bar.SetTotal(300, true) }() + max := 200 * time.Millisecond for i := 0; i < 300; i++ { if i == 140 { close(totalUpd1) @@ -47,7 +48,7 @@ if i == 250 { close(totalUpd2) } - time.Sleep(time.Duration(rand.Intn(10)+1) * (200 * time.Millisecond) / 10) + time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10) bar.Increment() } diff --git a/examples/panic/main.go b/examples/panic/main.go index 1a0e8ea..b50ac94 100644 --- a/examples/panic/main.go +++ b/examples/panic/main.go @@ -21,7 +21,7 @@ name := fmt.Sprintf("b#%02d:", i) bar := p.AddBar(100, mpb.BarID(i), mpb.PrependDecorators( func(s *decor.Statistics, _ chan<- int, _ <-chan int) string { - if s.ID == 2 && s.Current >= 42 { + if s.ID == 2 && s.Current == 42 { panic(wantPanic) } return name diff --git a/examples/prependETA/main.go b/examples/prependETA/main.go index 3a2c5d7..974bc6a 100644 --- a/examples/prependETA/main.go +++ b/examples/prependETA/main.go @@ -37,8 +37,9 @@ ) go func() { defer wg.Done() + max := 200 * time.Millisecond for i := 0; i < total; i++ { - time.Sleep(time.Duration(rand.Intn(10)+1) * (200 * time.Millisecond) / 10) + time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10) b.Increment() } }() diff --git a/examples/prependElapsed/main.go b/examples/prependElapsed/main.go index e0a336a..3cc0ae2 100644 --- a/examples/prependElapsed/main.go +++ b/examples/prependElapsed/main.go @@ -38,8 +38,9 @@ ) go func() { defer wg.Done() + max := 200 * time.Millisecond for i := 0; i < total; i++ { - time.Sleep(time.Duration(rand.Intn(10)+1) * (200 * time.Millisecond) / 10) + time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10) b.Increment() } }() diff --git a/examples/remove/main.go b/examples/remove/main.go index 9e7ea5e..12d5bef 100644 --- a/examples/remove/main.go +++ b/examples/remove/main.go @@ -37,8 +37,9 @@ ) go func() { defer wg.Done() + max := 200 * time.Millisecond for i := 0; i < total; i++ { - time.Sleep(time.Duration(rand.Intn(10)+1) * (200 * time.Millisecond) / 10) + time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10) b.Increment() if b.ID() == 1 && i == 42 { p.RemoveBar(b) diff --git a/examples/sort/main.go b/examples/sort/main.go index 03a54c5..c6bd673 100644 --- a/examples/sort/main.go +++ b/examples/sort/main.go @@ -37,8 +37,9 @@ ) go func() { defer wg.Done() + max := 200 * time.Millisecond for i := 0; i < total; i++ { - time.Sleep(time.Duration(rand.Intn(10)+1) * (200 * time.Millisecond) / 10) + time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10) if i&1 == 1 { priority := total - int(b.Current()) p.UpdateBarPriority(b, priority) diff --git a/examples/stress/main.go b/examples/stress/main.go index 330d45d..6a3d72a 100644 --- a/examples/stress/main.go +++ b/examples/stress/main.go @@ -39,8 +39,9 @@ go func() { defer wg.Done() + max := 300 * time.Millisecond for i := 0; i < total; i++ { - time.Sleep(time.Duration(rand.Intn(10)+1) * (200 * time.Millisecond) / 10) + time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10) bar.Increment() } }()