Codebase list golang-github-vbauerster-mpb / 870030c
increment bar with random value Vladimir Bauer 4 years ago
1 changed file(s) with 4 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
2727 ),
2828 mpb.AppendDecorators(decor.Percentage(decor.WC{W: 5})),
2929 )
30 go complete(bars[i], i+1)
30 go complete(bars[i])
3131 }
3232
3333 for i := 0; i < numBars; i++ {
3434 afterBar := bars[i]
3535 task := fmt.Sprintf("Task#%02d:", i)
36 incrBy := numBars - i
3736 go func() {
3837 job := "\x1b[31minstalling\x1b[0m"
3938 // preparing queued bars
4948 decor.OnComplete(decor.Percentage(decor.WC{W: 5}), ""),
5049 ),
5150 )
52 complete(b, incrBy) // blocks until afterBar completes
51 complete(b) // blocks until afterBar completes
5352 }()
5453 }
5554
5655 p.Wait()
5756 }
5857
59 func complete(bar *mpb.Bar, incrBy int) {
58 func complete(bar *mpb.Bar) {
6059 max := 100 * time.Millisecond
6160 for !bar.Completed() {
6261 // start variable is solely for EWMA calculation
6362 // EWMA's unit of measure is an iteration's duration
6463 start := time.Now()
6564 time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
66 bar.IncrBy(incrBy)
65 bar.IncrInt64(rand.Int63n(5) + 1)
6766 // we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract
6867 bar.DecoratorEwmaUpdate(time.Since(start))
6968 }