address issue #67
Vladimir Bauer
5 years ago
| 39 | 39 |
|
| 40 | 40 |
// WithManualRefresh disables internal auto refresh time.Ticker.
|
| 41 | 41 |
// Refresh will occur upon receive value from provided ch.
|
| 42 | |
func WithManualRefresh(ch <-chan time.Time) ContainerOption {
|
|
42 |
func WithManualRefresh(ch <-chan interface{}) ContainerOption {
|
| 43 | 43 |
return func(s *pState) {
|
| 44 | |
s.refreshSrc = ch
|
|
44 |
s.externalRefresh = ch
|
| 45 | 45 |
}
|
| 46 | 46 |
}
|
| 47 | 47 |
|
|
| 69 | 69 |
func WithOutput(w io.Writer) ContainerOption {
|
| 70 | 70 |
return func(s *pState) {
|
| 71 | 71 |
if w == nil {
|
| 72 | |
s.refreshSrc = make(chan time.Time)
|
| 73 | 72 |
s.output = ioutil.Discard
|
|
73 |
s.outputDiscarded = true
|
| 74 | 74 |
return
|
| 75 | 75 |
}
|
| 76 | 76 |
s.output = w
|
| 45 | 45 |
idCount int
|
| 46 | 46 |
reqWidth int
|
| 47 | 47 |
popCompleted bool
|
|
48 |
outputDiscarded bool
|
| 48 | 49 |
rr time.Duration
|
| 49 | 50 |
uwg *sync.WaitGroup
|
| 50 | |
refreshSrc <-chan time.Time
|
|
51 |
externalRefresh <-chan interface{}
|
| 51 | 52 |
renderDelay <-chan struct{}
|
| 52 | 53 |
shutdownNotifier chan struct{}
|
| 53 | 54 |
parkedBars map[*Bar]*Bar
|
|
| 233 | 234 |
if s.renderDelay != nil {
|
| 234 | 235 |
<-s.renderDelay
|
| 235 | 236 |
}
|
| 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
|
| 240 | 246 |
}
|
| 241 | 247 |
for {
|
| 242 | 248 |
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 |
}
|
| 245 | 257 |
case <-done:
|
| 246 | 258 |
close(s.shutdownNotifier)
|
| 247 | 259 |
return
|