move rr to const block as prr
Vladimir Bauer
9 years ago
| 10 | 10 | "github.com/vbauerster/mpb/cwriter" |
| 11 | 11 | ) |
| 12 | 12 | |
| 13 | // default RefreshRate | |
| 14 | var rr = 100 * time.Millisecond | |
| 15 | ||
| 16 | 13 | type ( |
| 17 | 14 | // BeforeRender is a func, which gets called before render process |
| 18 | 15 | BeforeRender func([]*Bar) |
| 24 | 21 | |
| 25 | 22 | // config changeable by user |
| 26 | 23 | userConf struct { |
| 24 | bars []*Bar | |
| 25 | ||
| 27 | 26 | width int |
| 28 | 27 | format string |
| 29 | bars []*Bar | |
| 30 | beforeRender BeforeRender | |
| 28 | rr time.Duration | |
| 31 | 29 | cw *cwriter.Writer |
| 32 | 30 | ticker *time.Ticker |
| 31 | beforeRender BeforeRender | |
| 33 | 32 | |
| 34 | 33 | shutdownNotifier chan struct{} |
| 35 | 34 | cancel <-chan struct{} |
| 37 | 36 | ) |
| 38 | 37 | |
| 39 | 38 | const ( |
| 39 | // default RefreshRate | |
| 40 | prr = 100 * time.Millisecond | |
| 40 | 41 | // default width |
| 41 | 42 | pwidth = 80 |
| 42 | 43 | // default format |
| 73 | 74 | width: pwidth, |
| 74 | 75 | format: pformat, |
| 75 | 76 | cw: cwriter.New(os.Stdout), |
| 76 | ticker: time.NewTicker(rr), | |
| 77 | rr: prr, | |
| 78 | ticker: time.NewTicker(prr), | |
| 77 | 79 | }) |
| 78 | 80 | return p |
| 79 | 81 | } |
| 112 | 114 | |
| 113 | 115 | // RefreshRate overrides default (100ms) refresh rate value |
| 114 | 116 | func (p *Progress) RefreshRate(d time.Duration) *Progress { |
| 115 | rr = d // TODO: don't update global var | |
| 116 | 117 | return updateConf(p, func(c *userConf) { |
| 117 | 118 | c.ticker.Stop() |
| 118 | 119 | c.ticker = time.NewTicker(d) |
| 120 | c.rr = d | |
| 119 | 121 | }) |
| 120 | 122 | } |
| 121 | 123 | |
| 301 | 303 | } |
| 302 | 304 | |
| 303 | 305 | quitWidthSyncCh := make(chan struct{}) |
| 304 | time.AfterFunc(rr, func() { | |
| 306 | time.AfterFunc(conf.rr, func() { | |
| 305 | 307 | close(quitWidthSyncCh) |
| 306 | 308 | }) |
| 307 | 309 | |