Codebase list golang-github-vbauerster-mpb / bdfb41f
allow SetTotal to set zero total if total is negative it's set to current value. Vladimir Bauer 4 years ago
2 changed file(s) with 4 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
164164 }
165165
166166 // SetTotal sets total dynamically.
167 // If total is less than or equal to zero it takes progress' current value.
167 // If total is negative it takes progress' current value.
168168 func (b *Bar) SetTotal(total int64, triggerComplete bool) {
169169 select {
170170 case b.operateState <- func(s *bState) {
171171 s.triggerComplete = triggerComplete
172 if total <= 0 {
172 if total < 0 {
173173 s.total = s.current
174174 } else {
175175 s.total = total
1414 n, err := x.ReadCloser.Read(p)
1515 x.bar.IncrBy(n)
1616 if err == io.EOF {
17 go x.bar.SetTotal(0, true)
17 go x.bar.SetTotal(-1, true)
1818 }
1919 return n, err
2020 }
2929 n, err := x.wt.WriteTo(w)
3030 x.bar.IncrInt64(n)
3131 if err == io.EOF {
32 go x.bar.SetTotal(0, true)
32 go x.bar.SetTotal(-1, true)
3333 }
3434 return n, err
3535 }