Codebase list golang-github-vbauerster-mpb / 554493c
Refactor examples Vladimir Bauer 8 years ago
11 changed file(s) with 50 addition(s) and 77 deletion(s). Raw diff Collapse all Expand all
5959 )
6060
6161 for i := 0; i < total; i++ {
62 time.Sleep(time.Duration(rand.Intn(10)+1) * time.Second / 100)
62 time.Sleep(time.Duration(rand.Intn(10)+1) * (200 * time.Millisecond) / 10)
6363 bar.Increment()
6464 }
6565 // Gracefully shutdown mpb's monitor goroutine
8585 decor.Percentage(3, decor.DSyncSpace),
8686 ),
8787 mpb.AppendDecorators(
88 decor.ETA(2, 0),
88 decor.ETA(3, 0),
8989 ),
9090 )
9191 go func() {
9292 defer wg.Done()
9393 for i := 0; i < total; i++ {
94 time.Sleep(time.Duration(rand.Intn(10)+1) * time.Second / 100)
94 time.Sleep(time.Duration(rand.Intn(10)+1) * (200 * time.Millisecond) / 10)
9595 bar.Increment()
9696 }
9797 }()
3838 )
3939
4040 for i := 0; i < total; i++ {
41 time.Sleep(time.Duration(rand.Intn(10)+1) * time.Second / 100)
41 time.Sleep(time.Duration(rand.Intn(10)+1) * (200 * time.Millisecond) / 10)
4242 bar.Increment()
4343 }
4444
5050 bar := p.AddBar(100, mpb.AppendDecorators(decor.Percentage(5, 0)))
5151
5252 for !bar.Completed() {
53 time.Sleep(time.Duration(rand.Intn(10)+1) * time.Second / 100)
53 time.Sleep(time.Duration(rand.Intn(10)+1) * (200 * time.Millisecond) / 10)
5454 bar.Increment()
5555 }
5656 }
1212 "github.com/vbauerster/mpb/decor"
1313 )
1414
15 const (
16 maxBlockSize = 12
17 )
15 func init() {
16 rand.Seed(time.Now().UnixNano())
17 }
1818
1919 func main() {
20
2120 ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
2221 defer cancel()
2322
2625 mpb.WithWaitGroup(&wg),
2726 mpb.WithContext(ctx),
2827 )
29 total := 100
28 total := 300
3029 numBars := 3
3130 wg.Add(numBars)
3231
3332 for i := 0; i < numBars; i++ {
3433 name := fmt.Sprintf("Bar#%d:", i)
35 bar := p.AddBar(int64(total), mpb.BarID(i),
34 bar := p.AddBar(int64(total),
3635 mpb.PrependDecorators(
3736 decor.StaticName(name, 0, decor.DwidthSync|decor.DidentRight),
3837 decor.ETA(4, decor.DSyncSpace),
4140 decor.Percentage(5, 0),
4241 ),
4342 )
43
4444 go func() {
4545 defer wg.Done()
46 blockSize := rand.Intn(maxBlockSize) + 1
47 for i := 0; i < total; i++ {
48 select {
49 case <-ctx.Done():
50 return
51 default:
52 }
53 sleep(blockSize)
46 for !bar.Completed() {
47 time.Sleep(randomDuration(200 * time.Millisecond))
5448 bar.Increment()
55 blockSize = rand.Intn(maxBlockSize) + 1
5649 }
5750 }()
5851 }
6154 fmt.Println("stop")
6255 }
6356
64 func sleep(blockSize int) {
65 time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond)))))
57 func randomDuration(max time.Duration) time.Duration {
58 return time.Duration(rand.Intn(10)+1) * max / 10
6659 }
66 "github.com/vbauerster/mpb"
77 "github.com/vbauerster/mpb/decor"
88 )
9
10 func init() {
11 rand.Seed(time.Now().UnixNano())
12 }
913
1014 func main() {
1115 p := mpb.New()
4246 if i == 250 {
4347 close(totalUpd2)
4448 }
45 time.Sleep(time.Duration(rand.Intn(10)+1) * time.Second / 100)
49 time.Sleep(time.Duration(rand.Intn(10)+1) * (200 * time.Millisecond) / 10)
4650 bar.Increment()
4751 }
4852
99 "github.com/vbauerster/mpb/decor"
1010 )
1111
12 const (
13 maxBlockSize = 12
14 )
12 func init() {
13 rand.Seed(time.Now().UnixNano())
14 }
1515
1616 func main() {
17
1817 var wg sync.WaitGroup
1918 p := mpb.New(mpb.WithWaitGroup(&wg))
2019 total := 100
3736 )
3837 go func() {
3938 defer wg.Done()
40 blockSize := rand.Intn(maxBlockSize) + 1
4139 for i := 0; i < total; i++ {
42 sleep(blockSize)
40 time.Sleep(time.Duration(rand.Intn(10)+1) * (200 * time.Millisecond) / 10)
4341 b.Increment()
44 blockSize = rand.Intn(maxBlockSize) + 1
4542 }
4643 }()
4744 }
4946 p.Stop()
5047 fmt.Println("stop")
5148 }
52
53 func sleep(blockSize int) {
54 time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond)))))
55 }
99 "github.com/vbauerster/mpb/decor"
1010 )
1111
12 const (
13 maxBlockSize = 12
14 )
12 func init() {
13 rand.Seed(time.Now().UnixNano())
14 }
1515
1616 func main() {
1717
3737 )
3838 go func() {
3939 defer wg.Done()
40 blockSize := rand.Intn(maxBlockSize) + 1
4140 for i := 0; i < total; i++ {
42 sleep(blockSize)
41 time.Sleep(time.Duration(rand.Intn(10)+1) * (200 * time.Millisecond) / 10)
4342 b.Increment()
44 blockSize = rand.Intn(maxBlockSize) + 1
4543 }
4644 }()
4745 }
4947 p.Stop()
5048 fmt.Println("stop")
5149 }
52
53 func sleep(blockSize int) {
54 time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond)))))
55 }
99 "github.com/vbauerster/mpb/decor"
1010 )
1111
12 const (
13 maxBlockSize = 12
14 )
12 func init() {
13 rand.Seed(time.Now().UnixNano())
14 }
1515
1616 func main() {
17
1817 var wg sync.WaitGroup
1918 p := mpb.New(mpb.WithWaitGroup(&wg))
2019 total := 100
3736 )
3837 go func() {
3938 defer wg.Done()
40 blockSize := rand.Intn(maxBlockSize) + 1
4139 for i := 0; i < total; i++ {
42 sleep(blockSize)
40 time.Sleep(time.Duration(rand.Intn(10)+1) * (200 * time.Millisecond) / 10)
4341 b.Increment()
44 blockSize = rand.Intn(maxBlockSize) + 1
4542 if b.ID() == 1 && i >= 42 {
4643 p.RemoveBar(b)
4744 return
5350 p.Stop()
5451 fmt.Println("stop")
5552 }
56
57 func sleep(blockSize int) {
58 time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond)))))
59 }
88 "github.com/vbauerster/mpb"
99 "github.com/vbauerster/mpb/decor"
1010 )
11
12 func init() {
13 rand.Seed(time.Now().UnixNano())
14 }
1115
1216 func main() {
1317 var wg sync.WaitGroup
2731 decor.Percentage(3, decor.DSyncSpace),
2832 ),
2933 mpb.AppendDecorators(
30 decor.ETA(2, 0),
34 decor.ETA(3, 0),
3135 ),
3236 )
3337 go func() {
3438 defer wg.Done()
3539 for i := 0; i < total; i++ {
36 time.Sleep(time.Duration(rand.Intn(10)+1) * time.Second / 100)
40 time.Sleep(time.Duration(rand.Intn(10)+1) * (200 * time.Millisecond) / 10)
3741 bar.Increment()
3842 }
3943 }()
3838 )
3939
4040 for i := 0; i < total; i++ {
41 time.Sleep(time.Duration(rand.Intn(10)+1) * time.Second / 100)
41 time.Sleep(time.Duration(rand.Intn(10)+1) * (200 * time.Millisecond) / 10)
4242 bar.Increment()
4343 }
4444 // Gracefully shutdown mpb's monitor goroutine
99 "github.com/vbauerster/mpb/decor"
1010 )
1111
12 const (
13 maxBlockSize = 12
14 )
12 func init() {
13 rand.Seed(time.Now().UnixNano())
14 }
1515
1616 func main() {
1717 var wg sync.WaitGroup
3636 )
3737 go func() {
3838 defer wg.Done()
39 for blockSize, i := 0, 0; i < total; i++ {
40 blockSize = rand.Intn(maxBlockSize) + 1
39 for i := 0; i < total; i++ {
40 time.Sleep(time.Duration(rand.Intn(10)+1) * (200 * time.Millisecond) / 10)
4141 if i&1 == 1 {
4242 priority := total - int(b.Current())
4343 p.UpdateBarPriority(b, priority)
4444 }
4545 b.Increment()
46 sleep(blockSize)
4746 }
4847 }()
4948 }
5150 p.Stop()
5251 fmt.Println("stop")
5352 }
54
55 func sleep(blockSize int) {
56 time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond)))))
57 }
1010 )
1111
1212 const (
13 totalBars = 32
14 maxBlockSize = 8
13 totalBars = 32
1514 )
15
16 func init() {
17 rand.Seed(time.Now().UnixNano())
18 }
1619
1720 func main() {
1821
3538
3639 go func() {
3740 defer wg.Done()
38 blockSize := rand.Intn(maxBlockSize) + 1
3941 for i := 0; i < total; i++ {
40 sleep(blockSize)
42 time.Sleep(time.Duration(rand.Intn(10)+1) * (200 * time.Millisecond) / 10)
4143 bar.Increment()
42 blockSize = rand.Intn(maxBlockSize) + 1
4344 }
4445 }()
4546 }
4748 p.Stop()
4849 fmt.Println("stop")
4950 }
50
51 func sleep(blockSize int) {
52 time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond)))))
53 }