diff --git a/container_option.go b/container_option.go index f78b3a0..f238b1d 100644 --- a/container_option.go +++ b/container_option.go @@ -42,6 +42,7 @@ func WithManualRefresh(ch <-chan interface{}) ContainerOption { return func(s *pState) { s.externalRefresh = ch + s.disableAutoRefresh = true } } diff --git a/progress.go b/progress.go index e1dad63..f2cb7c6 100644 --- a/progress.go +++ b/progress.go @@ -30,7 +30,6 @@ operateState chan func(*pState) interceptIo chan func(io.Writer) done chan struct{} - refreshCh chan time.Time once sync.Once cancel func() } @@ -47,19 +46,20 @@ pool []*Bar // following are provided/overrided by user - idCount int - reqWidth int - popPriority int - popCompleted bool - outputDiscarded bool - rr time.Duration - uwg *sync.WaitGroup - externalRefresh <-chan interface{} - renderDelay <-chan struct{} - shutdownNotifier chan struct{} - queueBars map[*Bar]*Bar - output io.Writer - debugOut io.Writer + idCount int + reqWidth int + popPriority int + popCompleted bool + outputDiscarded bool + disableAutoRefresh bool + rr time.Duration + uwg *sync.WaitGroup + externalRefresh <-chan interface{} + renderDelay <-chan struct{} + shutdownNotifier chan struct{} + queueBars map[*Bar]*Bar + output io.Writer + debugOut io.Writer } // New creates new Progress container instance. It's not possible to @@ -375,22 +375,20 @@ s.shutdownNotifier = make(chan struct{}) } go func() { - if s.renderDelay != nil { - <-s.renderDelay - } - var internalRefresh <-chan time.Time - if !s.outputDiscarded { - if s.externalRefresh == nil { + var autoRefresh <-chan time.Time + if !s.disableAutoRefresh { + if !s.outputDiscarded { + if s.renderDelay != nil { + <-s.renderDelay + } ticker := time.NewTicker(s.rr) defer ticker.Stop() - internalRefresh = ticker.C - } - } else { - s.externalRefresh = nil + autoRefresh = ticker.C + } } for { select { - case t := <-internalRefresh: + case t := <-autoRefresh: ch <- t case x := <-s.externalRefresh: if t, ok := x.(time.Time); ok {