Codebase list golang-github-vbauerster-mpb / 1e03587
Update cancel example Vladimir Bauer 9 years ago
1 changed file(s) with 11 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
99 "time"
1010
1111 "github.com/vbauerster/mpb"
12 "github.com/vbauerster/mpb/decor"
1213 )
1314
1415 const (
2021 ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
2122 defer cancel()
2223
23 p := mpb.New().WithContext(ctx)
24 p := mpb.New(mpb.WithContext(ctx))
2425
2526 var wg sync.WaitGroup
2627 total := 100
2930
3031 for i := 0; i < numBars; i++ {
3132 name := fmt.Sprintf("Bar#%d:", i)
32 bar := p.AddBarWithID(i, int64(total)).
33 PrependName(name, 0, mpb.DwidthSync|mpb.DidentRight).
34 PrependETA(4, mpb.DwidthSync|mpb.DextraSpace).
35 AppendPercentage(5, 0)
33 bar := p.AddBar(int64(total), mpb.BarID(i),
34 mpb.PrependDecorators(
35 decor.Name(name, 0, decor.DwidthSync|decor.DidentRight),
36 decor.ETA(4, decor.DSyncSpace),
37 ),
38 mpb.AppendDecorators(
39 decor.Percentage(5, 0),
40 ),
41 )
3642 go func() {
3743 defer func() {
3844 // fmt.Printf("%s done\n", name)