diff --git a/bar.go b/bar.go index a39785c..ac815aa 100644 --- a/bar.go +++ b/bar.go @@ -61,7 +61,7 @@ type renderFrame struct { rows []io.Reader - shutdown int + shutdown bool err error } @@ -401,6 +401,7 @@ } func (b *Bar) render(tw int) { + var done bool fn := func(s *bState) { var rows []io.Reader stat := newStatistics(tw, s) @@ -419,8 +420,7 @@ } frame := &renderFrame{rows: rows} if s.completed || s.aborted { - s.shutdown++ - frame.shutdown = s.shutdown + frame.shutdown = !done || s.shutdown == 1 b.cancel() } b.frameCh <- frame @@ -428,6 +428,7 @@ select { case b.operateState <- fn: case <-b.done: + done = true fn(b.bs) } } diff --git a/progress.go b/progress.go index 178ad17..2bd9888 100644 --- a/progress.go +++ b/progress.go @@ -342,27 +342,28 @@ }() } } - if frame.shutdown != 0 { + if frame.shutdown { b.Wait() // waiting for b.done, so it's safe to read b.bs - drop := b.bs.dropOnComplete if qb, ok := s.queueBars[b]; ok { delete(s.queueBars, b) qb.priority = b.priority s.pool = append(s.pool, qb) - drop = true - } else if s.popCompleted && !b.bs.noPop { - switch frame.shutdown { + s.heapUpdated = true + continue + } + if s.popCompleted && !b.bs.noPop { + switch b.bs.shutdown++; b.bs.shutdown { case 1: b.priority = s.popPriority s.popPriority++ - drop = false default: - if drop { + if b.bs.dropOnComplete { popCount += usedRows + s.heapUpdated = true + continue } } - } - if drop { + } else if b.bs.dropOnComplete { s.heapUpdated = true continue }