unblocking SetTotal
Vladimir Bauer
7 years ago
| 178 | 178 | |
| 179 | 179 | // SetTotal sets total dynamically. |
| 180 | 180 | // Set final to true, when total is known, it will trigger bar complete event. |
| 181 | func (b *Bar) SetTotal(total int64, final bool) { | |
| 182 | b.operateState <- func(s *bState) { | |
| 181 | func (b *Bar) SetTotal(total int64, final bool) bool { | |
| 182 | select { | |
| 183 | case b.operateState <- func(s *bState) { | |
| 183 | 184 | if total > 0 { |
| 184 | 185 | s.total = total |
| 185 | 186 | } |
| 187 | 188 | s.current = s.total |
| 188 | 189 | s.toComplete = true |
| 189 | 190 | } |
| 191 | }: | |
| 192 | return true | |
| 193 | case <-b.done: | |
| 194 | return false | |
| 190 | 195 | } |
| 191 | 196 | } |
| 192 | 197 | |