allow SetTotal to set zero total
if total is negative it's set to current value.
Vladimir Bauer
4 years ago
| 164 | 164 |
}
|
| 165 | 165 |
|
| 166 | 166 |
// 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.
|
| 168 | 168 |
func (b *Bar) SetTotal(total int64, triggerComplete bool) {
|
| 169 | 169 |
select {
|
| 170 | 170 |
case b.operateState <- func(s *bState) {
|
| 171 | 171 |
s.triggerComplete = triggerComplete
|
| 172 | |
if total <= 0 {
|
|
172 |
if total < 0 {
|
| 173 | 173 |
s.total = s.current
|
| 174 | 174 |
} else {
|
| 175 | 175 |
s.total = total
|
| 14 | 14 |
n, err := x.ReadCloser.Read(p)
|
| 15 | 15 |
x.bar.IncrBy(n)
|
| 16 | 16 |
if err == io.EOF {
|
| 17 | |
go x.bar.SetTotal(0, true)
|
|
17 |
go x.bar.SetTotal(-1, true)
|
| 18 | 18 |
}
|
| 19 | 19 |
return n, err
|
| 20 | 20 |
}
|
|
| 29 | 29 |
n, err := x.wt.WriteTo(w)
|
| 30 | 30 |
x.bar.IncrInt64(n)
|
| 31 | 31 |
if err == io.EOF {
|
| 32 | |
go x.bar.SetTotal(0, true)
|
|
32 |
go x.bar.SetTotal(-1, true)
|
| 33 | 33 |
}
|
| 34 | 34 |
return n, err
|
| 35 | 35 |
}
|