diff --git a/bar.go b/bar.go index b78fa47..ed53c2f 100644 --- a/bar.go +++ b/bar.go @@ -173,13 +173,12 @@ } // EnableTriggerComplete enables triggering complete event. It's effective -// only for bars which were constructed with `total <= 0` and after total -// has been set with `(*Bar).SetTotal(int64, false)`. If `curren >= total` +// only for bars which were constructed with `total <= 0`. If `curren >= total` // at the moment of call, complete event is triggered right away. func (b *Bar) EnableTriggerComplete() { select { case b.operateState <- func(s *bState) { - if s.triggerComplete || s.total <= 0 { + if s.triggerComplete { return } if s.current >= s.total { diff --git a/bar_test.go b/bar_test.go index 2473ae4..1fefd8d 100644 --- a/bar_test.go +++ b/bar_test.go @@ -62,6 +62,25 @@ bar.SetTotal(0, true) if !bar.Completed() { t.Error("expected bar to complete") + } + + p.Wait() +} + +func TestBarEnableTriggerCompleteZeroBar(t *testing.T) { + p := mpb.New(mpb.WithWidth(80), mpb.WithOutput(io.Discard)) + bar := p.AddBar(0) // never complete bar + + if bar.Completed() { + t.Fail() + } + + // Calling bar.SetTotal(0, true) has same effect + // but this one is more concise and intuitive + bar.EnableTriggerComplete() + + if !bar.Completed() { + t.Fail() } p.Wait()