setting total to 0 never completes
Vladimir Bauer
7 years ago
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | // SetTotal sets total dynamically. |
| 172 | // Set final to true, when total is known, it will trigger bar complete event. | |
| 173 | func (b *Bar) SetTotal(total int64, final bool) bool { | |
| 172 | // Set toComplete to true, to trigger bar complete event now. | |
| 173 | func (b *Bar) SetTotal(total int64, toComplete bool) { | |
| 174 | 174 | select { |
| 175 | 175 | case b.operateState <- func(s *bState) { |
| 176 | if total > 0 { | |
| 177 | s.total = total | |
| 178 | } | |
| 179 | if final && !s.toComplete { | |
| 176 | s.total = total | |
| 177 | if toComplete && !s.toComplete { | |
| 180 | 178 | s.current = s.total |
| 181 | 179 | s.toComplete = true |
| 182 | 180 | go b.refreshNowTillShutdown() |
| 183 | 181 | } |
| 184 | 182 | }: |
| 185 | return true | |
| 186 | case <-b.done: | |
| 187 | return false | |
| 183 | case <-b.done: | |
| 188 | 184 | } |
| 189 | 185 | } |
| 190 | 186 | |
| 212 | 208 | select { |
| 213 | 209 | case b.operateState <- func(s *bState) { |
| 214 | 210 | s.current += int64(n) |
| 215 | if s.current >= s.total && !s.toComplete { | |
| 211 | if s.total > 0 && s.current >= s.total { | |
| 216 | 212 | s.current = s.total |
| 217 | 213 | s.toComplete = true |
| 218 | 214 | go b.refreshNowTillShutdown() |