Codebase list golang-github-vbauerster-mpb / ed4401a
address issue #67 Vladimir Bauer 5 years ago
2 changed file(s) with 22 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
3939
4040 // WithManualRefresh disables internal auto refresh time.Ticker.
4141 // Refresh will occur upon receive value from provided ch.
42 func WithManualRefresh(ch <-chan time.Time) ContainerOption {
42 func WithManualRefresh(ch <-chan interface{}) ContainerOption {
4343 return func(s *pState) {
44 s.refreshSrc = ch
44 s.externalRefresh = ch
4545 }
4646 }
4747
6969 func WithOutput(w io.Writer) ContainerOption {
7070 return func(s *pState) {
7171 if w == nil {
72 s.refreshSrc = make(chan time.Time)
7372 s.output = ioutil.Discard
73 s.outputDiscarded = true
7474 return
7575 }
7676 s.output = w
4545 idCount int
4646 reqWidth int
4747 popCompleted bool
48 outputDiscarded bool
4849 rr time.Duration
4950 uwg *sync.WaitGroup
50 refreshSrc <-chan time.Time
51 externalRefresh <-chan interface{}
5152 renderDelay <-chan struct{}
5253 shutdownNotifier chan struct{}
5354 parkedBars map[*Bar]*Bar
233234 if s.renderDelay != nil {
234235 <-s.renderDelay
235236 }
236 if s.refreshSrc == nil {
237 ticker := time.NewTicker(s.rr)
238 defer ticker.Stop()
239 s.refreshSrc = ticker.C
237 var internalRefresh <-chan time.Time
238 if !s.outputDiscarded {
239 if s.externalRefresh == nil {
240 ticker := time.NewTicker(s.rr)
241 defer ticker.Stop()
242 internalRefresh = ticker.C
243 }
244 } else {
245 s.externalRefresh = nil
240246 }
241247 for {
242248 select {
243 case tick := <-s.refreshSrc:
244 ch <- tick
249 case t := <-internalRefresh:
250 ch <- t
251 case x := <-s.externalRefresh:
252 if t, ok := x.(time.Time); ok {
253 ch <- t
254 } else {
255 ch <- time.Now()
256 }
245257 case <-done:
246258 close(s.shutdownNotifier)
247259 return