better performance
Vladimir Bauer
7 years ago
| 105 | 105 | operateState: make(chan func(*bState)), |
| 106 | 106 | frameCh: make(chan io.Reader, 1), |
| 107 | 107 | syncTableCh: make(chan [][]chan int), |
| 108 | completed: make(chan bool), | |
| 108 | completed: make(chan bool, 1), | |
| 109 | 109 | done: make(chan struct{}), |
| 110 | 110 | cancel: cancel, |
| 111 | 111 | dlogger: log.New(bs.debugOut, logPrefix, log.Lshortfile), |
| 255 | 255 | // Completed reports whether the bar is in completed state. |
| 256 | 256 | func (b *Bar) Completed() bool { |
| 257 | 257 | select { |
| 258 | case completed := <-b.completed: | |
| 259 | return completed | |
| 258 | case b.operateState <- func(s *bState) { b.completed <- s.toComplete }: | |
| 259 | return <-b.completed | |
| 260 | 260 | case <-b.done: |
| 261 | 261 | return true |
| 262 | 262 | } |
| 277 | 277 | select { |
| 278 | 278 | case op := <-b.operateState: |
| 279 | 279 | op(s) |
| 280 | case b.completed <- s.toComplete: | |
| 281 | 280 | case <-ctx.Done(): |
| 282 | 281 | b.cacheState = s |
| 283 | 282 | close(b.done) |