Codebase list golang-github-vbauerster-mpb / 8326db7
EnableTriggerComplete without total <= 0 check Enables completing zero total bar without calling SetTotal(0, true). Vladimir Bauer 1 year, 11 months ago
2 changed file(s) with 21 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
172172 }
173173
174174 // EnableTriggerComplete enables triggering complete event. It's effective
175 // only for bars which were constructed with `total <= 0` and after total
176 // has been set with `(*Bar).SetTotal(int64, false)`. If `curren >= total`
175 // only for bars which were constructed with `total <= 0`. If `curren >= total`
177176 // at the moment of call, complete event is triggered right away.
178177 func (b *Bar) EnableTriggerComplete() {
179178 select {
180179 case b.operateState <- func(s *bState) {
181 if s.triggerComplete || s.total <= 0 {
180 if s.triggerComplete {
182181 return
183182 }
184183 if s.current >= s.total {
6161 bar.SetTotal(0, true)
6262 if !bar.Completed() {
6363 t.Error("expected bar to complete")
64 }
65
66 p.Wait()
67 }
68
69 func TestBarEnableTriggerCompleteZeroBar(t *testing.T) {
70 p := mpb.New(mpb.WithWidth(80), mpb.WithOutput(io.Discard))
71 bar := p.AddBar(0) // never complete bar
72
73 if bar.Completed() {
74 t.Fail()
75 }
76
77 // Calling bar.SetTotal(0, true) has same effect
78 // but this one is more concise and intuitive
79 bar.EnableTriggerComplete()
80
81 if !bar.Completed() {
82 t.Fail()
6483 }
6584
6685 p.Wait()