Codebase list golang-github-vbauerster-mpb / f15addf example / gifs / cancel.gif
readme: add cancel example Vladimir Bauer 9 years ago
7 changed file(s) with 16 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
99 ## Features
1010
1111 * __Multiple Bars__: mpb can render multiple progress bars that can be tracked concurrently
12 * __Cancellable__: cancel rendering goroutine at any time
1213 * __Dynamic Addition__: Add additional progress bar at any time
1314 * __Dynamic Removal__: Remove rendering progress bar at any time
1415 * __Dynamic Sorting__: Sort bars by progression
2223
2324 ```go
2425 name := "Single bar:"
25 p := mpb.New()
26 // Star mpb's rendering goroutine.
27 // If you don't plan to cancel, feed with nil
28 // otherwise provide context.Context, see cancel example
29 p := mpb.New(nil)
2630 bar := p.AddBar(100).PrependName(name, 0).AppendPercentage()
2731
2832 for i := 0; i < 100; i++ {
3943
4044 ```go
4145 var wg sync.WaitGroup
42 p := mpb.New() // Star mpb's rendering goroutine
46 p := mpb.New(nil)
4347 for i := 0; i < 3; i++ {
4448 wg.Add(1) // add wg delta
4549 name := fmt.Sprintf("Bar#%d:", i)
6468 ![example](example/gifs/simple.gif)
6569
6670 The source code: [example/simple/main.go](example/simple/main.go)
71
72 ### Cancel
73
74 ![example](example/gifs/cancel.gif)
75
76 The source code: [example/cancel/main.go](example/cancel/main.go)
6777
6878 ### Removing bar
6979
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown
1010
1111 func main() {
1212 var wg sync.WaitGroup
13 p := mpb.New(nil) // Star mpb's rendering goroutine
13 p := mpb.New(nil)
1414 for i := 0; i < 3; i++ {
1515 wg.Add(1) // add wg delta
1616 name := fmt.Sprintf("Bar#%d:", i)
1010 func main() {
1111
1212 name := "Single bar:"
13 // Star mpb's rendering goroutine.
14 // If you don't plan to cancel, feed with nil
15 // otherwise provide context.Context, see cancel example
1316 p := mpb.New(nil)
1417 bar := p.AddBar(100).PrependName(name, 0).AppendPercentage()
1518