diff --git a/progress.go b/progress.go index bcdaaf0..b5374b6 100644 --- a/progress.go +++ b/progress.go @@ -65,6 +65,7 @@ barCountReqCh chan chan int brCh chan BeforeRender done chan struct{} + beforeStop chan struct{} cancel <-chan struct{} } @@ -80,6 +81,7 @@ barCountReqCh: make(chan chan int), brCh: make(chan BeforeRender), done: make(chan struct{}), + beforeStop: make(chan struct{}), wg: new(sync.WaitGroup), } go p.server() @@ -198,10 +200,11 @@ // 100 %. It is NOT for cancelation. Use WithContext or WithCancel for // cancelation purposes. func (p *Progress) Stop() { + if isClosed(p.done) { + return + } + p.beforeStop <- struct{}{} p.wg.Wait() - if isClosed(p.done) { - return - } close(p.bCommandCh) } @@ -298,6 +301,12 @@ case userRR = <-p.rrChangeReqCh: t.Stop() t = time.NewTicker(userRR) + case <-p.beforeStop: + for _, b := range bars { + if b.GetStatistics().Total <= 0 { + b.Completed() + } + } case <-p.cancel: return }