Codebase list golang-github-vbauerster-mpb / a0bd10c
Remove complete example Vladimir Bauer 8 years ago
1 changed file(s) with 0 addition(s) and 54 deletion(s). Raw diff Collapse all Expand all
+0
-54
examples/complete/main.go less more
0 package main
1
2 import (
3 "fmt"
4 "math/rand"
5 "sync"
6 "time"
7
8 "github.com/vbauerster/mpb"
9 "github.com/vbauerster/mpb/decor"
10 )
11
12 func init() {
13 rand.Seed(time.Now().UnixNano())
14 }
15
16 func main() {
17 var wg sync.WaitGroup
18 p := mpb.New(mpb.WithWaitGroup(&wg))
19 total := 100
20 numBars := 3
21 wg.Add(numBars)
22
23 for i := 0; i < numBars; i++ {
24 var name string
25 if i != 1 {
26 name = fmt.Sprintf("Bar#%d:", i)
27 }
28 b := p.AddBar(int64(total), mpb.BarID(i),
29 mpb.PrependDecorators(
30 decor.StaticName(name, 0, decor.DwidthSync|decor.DidentRight),
31 decor.ETA(4, decor.DSyncSpace),
32 ),
33 mpb.AppendDecorators(
34 decor.Percentage(5, 0),
35 ),
36 )
37 go func() {
38 defer wg.Done()
39 max := 100 * time.Millisecond
40 for i := 0; i < total; i++ {
41 if b.ID() == 1 && i == 42 {
42 b.Complete()
43 return
44 }
45 time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
46 b.Increment()
47 }
48 }()
49 }
50
51 p.Wait()
52 fmt.Println("done")
53 }