diff --git a/bar.go b/bar.go index d0333f6..a9131a0 100644 --- a/bar.go +++ b/bar.go @@ -144,7 +144,13 @@ // operation for example. func (b *Bar) SetRefill(amount int64) { select { - case b.operateState <- func(s *bState) { s.refill = amount }: + case b.operateState <- func(s *bState) { + if amount < s.current { + s.refill = amount + } else { + s.refill = s.current + } + }: case <-b.done: } } diff --git a/bar_test.go b/bar_test.go index db25d50..94136b0 100644 --- a/bar_test.go +++ b/bar_test.go @@ -147,8 +147,8 @@ bar := p.New(int64(total), mpb.BarStyle().Refiller(refiller), mpb.BarFillerTrim()) + bar.IncrBy(till) bar.SetRefill(int64(till)) - bar.IncrBy(till) bar.IncrBy(total - till) p.Wait()