Update cancel example
Vladimir Bauer
9 years ago
| 9 | 9 | "time" |
| 10 | 10 | |
| 11 | 11 | "github.com/vbauerster/mpb" |
| 12 | "github.com/vbauerster/mpb/decor" | |
| 12 | 13 | ) |
| 13 | 14 | |
| 14 | 15 | const ( |
| 20 | 21 | ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) |
| 21 | 22 | defer cancel() |
| 22 | 23 | |
| 23 | p := mpb.New().WithContext(ctx) | |
| 24 | p := mpb.New(mpb.WithContext(ctx)) | |
| 24 | 25 | |
| 25 | 26 | var wg sync.WaitGroup |
| 26 | 27 | total := 100 |
| 29 | 30 | |
| 30 | 31 | for i := 0; i < numBars; i++ { |
| 31 | 32 | 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 | ) | |
| 36 | 42 | go func() { |
| 37 | 43 | defer func() { |
| 38 | 44 | // fmt.Printf("%s done\n", name) |