InProgress example
Vladimir Bauer
9 years ago
| 23 | 23 | bar := p.AddBar(100).PrependName("Single Bar:", 0).AppendPercentage() |
| 24 | 24 | |
| 25 | 25 | for i := 0; i < 100; i++ { |
| 26 | bar.Incr(1) // increment progress bar | |
| 26 | 27 | time.Sleep(time.Duration(rand.Intn(100)) * time.Millisecond) |
| 27 | bar.Incr(1) | |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | // Don't forget to stop mpb's rendering goroutine |
| 33 | 33 | // You cannot add bars after p.Stop() has been called |
| 34 | 34 | // p.AddBar(100) // will panic |
| 35 | 35 | } |
| 36 | ||
| 37 | func ExampleBar_InProgress() { | |
| 38 | p := mpb.New(nil) | |
| 39 | bar := p.AddBar(100).AppendPercentage() | |
| 40 | ||
| 41 | for bar.InProgress() { | |
| 42 | bar.Incr(1) | |
| 43 | time.Sleep(time.Millisecond * 20) | |
| 44 | } | |
| 45 | } | |