Codebase list golang-github-vbauerster-mpb / e42dd41
bar SetRefill: make sure refill doesn't overflow current Vladimir Bauer 2 years ago
2 changed file(s) with 8 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
143143 // operation for example.
144144 func (b *Bar) SetRefill(amount int64) {
145145 select {
146 case b.operateState <- func(s *bState) { s.refill = amount }:
146 case b.operateState <- func(s *bState) {
147 if amount < s.current {
148 s.refill = amount
149 } else {
150 s.refill = s.current
151 }
152 }:
147153 case <-b.done:
148154 }
149155 }
146146
147147 bar := p.New(int64(total), mpb.BarStyle().Refiller(refiller), mpb.BarFillerTrim())
148148
149 bar.IncrBy(till)
149150 bar.SetRefill(int64(till))
150 bar.IncrBy(till)
151151 bar.IncrBy(total - till)
152152
153153 p.Wait()