Codebase list golang-github-vbauerster-mpb / fee1762
InProgress example Vladimir Bauer 9 years ago
1 changed file(s) with 11 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
2323 bar := p.AddBar(100).PrependName("Single Bar:", 0).AppendPercentage()
2424
2525 for i := 0; i < 100; i++ {
26 bar.Incr(1) // increment progress bar
2627 time.Sleep(time.Duration(rand.Intn(100)) * time.Millisecond)
27 bar.Incr(1)
2828 }
2929
3030 // Don't forget to stop mpb's rendering goroutine
3333 // You cannot add bars after p.Stop() has been called
3434 // p.AddBar(100) // will panic
3535 }
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 }