diff --git a/bar.go b/bar.go index 0ecdfc7..fc080f5 100644 --- a/bar.go +++ b/bar.go @@ -56,9 +56,11 @@ } type renderFrame struct { - rows []io.Reader - shutdown bool - err error + rows []io.Reader + shutdown int + rmOnComplete bool + noPop bool + err error } func newBar(ctx context.Context, container *Progress, bs *bState) *Bar { @@ -411,7 +413,6 @@ } func (b *Bar) render(tw int) { - var done bool fn := func(s *bState) { var rows []io.Reader stat := newStatistics(tw, s) @@ -428,17 +429,21 @@ return } } - frame := &renderFrame{rows: rows} + frame := &renderFrame{ + rows: rows, + shutdown: s.shutdown, + rmOnComplete: s.dropOnComplete, + noPop: s.noPop, + } if s.completed || s.aborted { - frame.shutdown = !done || s.shutdown == 1 - b.cancel() + // post increment makes sure OnComplete decorators are rendered + s.shutdown++ } b.frameCh <- frame } select { case b.operateState <- fn: case <-b.done: - done = true fn(b.bs) } } diff --git a/progress.go b/progress.go index f468221..cdfcb39 100644 --- a/progress.go +++ b/progress.go @@ -334,9 +334,9 @@ _, _ = io.Copy(io.Discard, row) } } - if frame.shutdown { - b.Wait() // waiting for b.done, so it's safe to read b.bs + if frame.shutdown != 0 { if qb, ok := s.queueBars[b]; ok { + b.cancel() delete(s.queueBars, b) qb.priority = b.priority wg.Add(1) @@ -346,19 +346,21 @@ }(qb) continue } - if s.popCompleted && !b.bs.noPop { - switch b.bs.shutdown++; b.bs.shutdown { + if s.popCompleted && !frame.noPop { + switch frame.shutdown { case 1: b.priority = s.popPriority s.popPriority++ default: - if b.bs.dropOnComplete { - popCount += usedRows - continue - } + b.cancel() + popCount += usedRows + continue } - } else if b.bs.dropOnComplete { + } else if frame.rmOnComplete { + b.cancel() continue + } else { + b.cancel() } } wg.Add(1)