SetTotal is nop after EnableTriggerComplete
Vladimir Bauer
1 year, 11 months ago
| 194 | 194 | |
| 195 | 195 | // SetTotal sets total to an arbitrary value. It's effective only for bar |
| 196 | 196 | // which was constructed with `total <= 0`. Setting total to negative value |
| 197 | // is equivalent to `(*Bar).SetTotal((*Bar).Current(), bool)` but faster. If | |
| 198 | // triggerCompletion is true, total value is set to current and complete | |
| 199 | // event is triggered right away. | |
| 200 | func (b *Bar) SetTotal(total int64, triggerCompletion bool) { | |
| 197 | // is equivalent to `(*Bar).SetTotal((*Bar).Current(), bool)` but faster. | |
| 198 | // If `complete` is true complete event is triggered right away. | |
| 199 | // Calling `(*Bar).EnableTriggerComplete` makes this one no operational. | |
| 200 | func (b *Bar) SetTotal(total int64, complete bool) { | |
| 201 | 201 | select { |
| 202 | 202 | case b.operateState <- func(s *bState) { |
| 203 | 203 | if s.triggerComplete { |
| 208 | 208 | } else { |
| 209 | 209 | s.total = total |
| 210 | 210 | } |
| 211 | if triggerCompletion { | |
| 211 | if complete { | |
| 212 | 212 | s.current = s.total |
| 213 | 213 | s.completed = true |
| 214 | 214 | b.triggerCompletion(s) |