make Abort method more atomic
Vladimir Bauer
4 years ago
| 266 | 266 | // if bar is already in complete state. If drop is true bar will be |
| 267 | 267 | // removed as well. |
| 268 | 268 | func (b *Bar) Abort(drop bool) { |
| 269 | if b.Completed() { | |
| 270 | return | |
| 271 | } | |
| 272 | select { | |
| 273 | case <-b.done: | |
| 274 | default: | |
| 269 | select { | |
| 270 | case b.operateState <- func(s *bState) { | |
| 271 | if s.completed == true { | |
| 272 | return | |
| 273 | } | |
| 275 | 274 | if drop { |
| 276 | 275 | b.container.dropBar(b) |
| 277 | } else if b.container.BarCount() == 1 { | |
| 276 | } else { | |
| 278 | 277 | b.container.refreshCh <- time.Now() |
| 279 | 278 | } |
| 280 | 279 | b.cancel() |
| 280 | }: | |
| 281 | <-b.done | |
| 282 | case <-b.done: | |
| 281 | 283 | } |
| 282 | 284 | } |
| 283 | 285 |