Codebase list golang-github-vbauerster-mpb / 9d97314
move rr to const block as prr Vladimir Bauer 9 years ago
1 changed file(s) with 10 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
1010 "github.com/vbauerster/mpb/cwriter"
1111 )
1212
13 // default RefreshRate
14 var rr = 100 * time.Millisecond
15
1613 type (
1714 // BeforeRender is a func, which gets called before render process
1815 BeforeRender func([]*Bar)
2421
2522 // config changeable by user
2623 userConf struct {
24 bars []*Bar
25
2726 width int
2827 format string
29 bars []*Bar
30 beforeRender BeforeRender
28 rr time.Duration
3129 cw *cwriter.Writer
3230 ticker *time.Ticker
31 beforeRender BeforeRender
3332
3433 shutdownNotifier chan struct{}
3534 cancel <-chan struct{}
3736 )
3837
3938 const (
39 // default RefreshRate
40 prr = 100 * time.Millisecond
4041 // default width
4142 pwidth = 80
4243 // default format
7374 width: pwidth,
7475 format: pformat,
7576 cw: cwriter.New(os.Stdout),
76 ticker: time.NewTicker(rr),
77 rr: prr,
78 ticker: time.NewTicker(prr),
7779 })
7880 return p
7981 }
112114
113115 // RefreshRate overrides default (100ms) refresh rate value
114116 func (p *Progress) RefreshRate(d time.Duration) *Progress {
115 rr = d // TODO: don't update global var
116117 return updateConf(p, func(c *userConf) {
117118 c.ticker.Stop()
118119 c.ticker = time.NewTicker(d)
120 c.rr = d
119121 })
120122 }
121123
301303 }
302304
303305 quitWidthSyncCh := make(chan struct{})
304 time.AfterFunc(rr, func() {
306 time.AfterFunc(conf.rr, func() {
305307 close(quitWidthSyncCh)
306308 })
307309