diff --git a/progress.go b/progress.go index 9cf8dc3..460d891 100644 --- a/progress.go +++ b/progress.go @@ -82,6 +82,7 @@ } // WithCancel cancellation via channel. +// You have to call p.Stop() anyway, after cancel. // Pancis, if nil channel is passed. func (p *Progress) WithCancel(ch <-chan struct{}) *Progress { if ch == nil { @@ -236,8 +237,6 @@ func (p *Progress) server(conf pConf) { defer func() { - conf.ticker.Stop() - conf.cw.Flush() p.conf = conf if conf.shutdownNotifier != nil { close(conf.shutdownNotifier) @@ -257,17 +256,8 @@ case op := <-p.ops: op(&conf) case <-conf.ticker.C: - var notick bool - select { - // stop ticking if cancel requested - case <-conf.cancel: - conf.ticker.Stop() - notick = true - default: - } - numBars := len(conf.bars) - if notick || numBars == 0 { + if numBars == 0 { break } @@ -302,7 +292,11 @@ for _, b := range conf.bars { b.flushed() } + case <-conf.cancel: + conf.ticker.Stop() + conf.cancel = nil case <-p.stopReqCh: + conf.ticker.Stop() return } } diff --git a/progress_go1.7.go b/progress_go1.7.go index 8e3556e..63d1dec 100644 --- a/progress_go1.7.go +++ b/progress_go1.7.go @@ -5,6 +5,7 @@ import "context" // WithContext cancellation via context. +// You have to call p.Stop() anyway, after cancel. // Pancis, if nil context is passed func (p *Progress) WithContext(ctx context.Context) *Progress { if ctx == nil {