readme: add cancel example
Vladimir Bauer
9 years ago
| 9 | 9 | ## Features |
| 10 | 10 | |
| 11 | 11 | * __Multiple Bars__: mpb can render multiple progress bars that can be tracked concurrently |
| 12 | * __Cancellable__: cancel rendering goroutine at any time | |
| 12 | 13 | * __Dynamic Addition__: Add additional progress bar at any time |
| 13 | 14 | * __Dynamic Removal__: Remove rendering progress bar at any time |
| 14 | 15 | * __Dynamic Sorting__: Sort bars by progression |
| 22 | 23 | |
| 23 | 24 | ```go |
| 24 | 25 | 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) | |
| 26 | 30 | bar := p.AddBar(100).PrependName(name, 0).AppendPercentage() |
| 27 | 31 | |
| 28 | 32 | for i := 0; i < 100; i++ { |
| 39 | 43 | |
| 40 | 44 | ```go |
| 41 | 45 | var wg sync.WaitGroup |
| 42 | p := mpb.New() // Star mpb's rendering goroutine | |
| 46 | p := mpb.New(nil) | |
| 43 | 47 | for i := 0; i < 3; i++ { |
| 44 | 48 | wg.Add(1) // add wg delta |
| 45 | 49 | name := fmt.Sprintf("Bar#%d:", i) |
| 64 | 68 |  |
| 65 | 69 | |
| 66 | 70 | The source code: [example/simple/main.go](example/simple/main.go) |
| 71 | ||
| 72 | ### Cancel | |
| 73 | ||
| 74 |  | |
| 75 | ||
| 76 | The source code: [example/cancel/main.go](example/cancel/main.go) | |
| 67 | 77 | |
| 68 | 78 | ### Removing bar |
| 69 | 79 | |
Binary diff not shown
Binary diff not shown
Binary diff not shown
Binary diff not shown
| 10 | 10 | |
| 11 | 11 | func main() { |
| 12 | 12 | var wg sync.WaitGroup |
| 13 | p := mpb.New(nil) // Star mpb's rendering goroutine | |
| 13 | p := mpb.New(nil) | |
| 14 | 14 | for i := 0; i < 3; i++ { |
| 15 | 15 | wg.Add(1) // add wg delta |
| 16 | 16 | name := fmt.Sprintf("Bar#%d:", i) |