bar SetRefill: make sure refill doesn't overflow current
Vladimir Bauer
2 years ago
| 143 | 143 | // operation for example. |
| 144 | 144 | func (b *Bar) SetRefill(amount int64) { |
| 145 | 145 | select { |
| 146 | case b.operateState <- func(s *bState) { s.refill = amount }: | |
| 146 | case b.operateState <- func(s *bState) { | |
| 147 | if amount < s.current { | |
| 148 | s.refill = amount | |
| 149 | } else { | |
| 150 | s.refill = s.current | |
| 151 | } | |
| 152 | }: | |
| 147 | 153 | case <-b.done: |
| 148 | 154 | } |
| 149 | 155 | } |