No critical to select in Completed, gain in performance
Vladimir Bauer
8 years ago
| 269 | 269 | // Completed reports whether the bar is in completed state |
| 270 | 270 | func (b *Bar) Completed() bool { |
| 271 | 271 | result := make(chan bool) |
| 272 | select { | |
| 273 | case b.operateState <- func(s *bState) { result <- s.toComplete }: | |
| 274 | return <-result | |
| 275 | case <-b.done: | |
| 276 | return b.cacheState.toComplete | |
| 277 | } | |
| 272 | b.operateState <- func(s *bState) { result <- s.toComplete } | |
| 273 | return <-result | |
| 278 | 274 | } |
| 279 | 275 | |
| 280 | 276 | func (b *Bar) serve(wg *sync.WaitGroup, s *bState, cancel <-chan struct{}) { |