make result chan inside Completed
there is no win in keeping it on bar instance.
Vladimir Bauer
4 years ago
| 26 | 26 | operateState chan func(*bState) |
| 27 | 27 | frameCh chan *frame |
| 28 | 28 | syncTableCh chan [][]chan int |
| 29 | completed chan bool | |
| 30 | 29 | |
| 31 | 30 | // cancel is called either by user or on complete event |
| 32 | 31 | cancel func() |
| 92 | 91 | operateState: make(chan func(*bState)), |
| 93 | 92 | frameCh: make(chan *frame, 1), |
| 94 | 93 | syncTableCh: make(chan [][]chan int, 1), |
| 95 | completed: make(chan bool, 1), | |
| 96 | 94 | done: make(chan struct{}), |
| 97 | 95 | cancel: cancel, |
| 98 | 96 | dlogger: log.New(bs.debugOut, logPrefix, log.Lshortfile), |
| 286 | 284 | |
| 287 | 285 | // Completed reports whether the bar is in completed state. |
| 288 | 286 | func (b *Bar) Completed() bool { |
| 289 | select { | |
| 290 | case b.operateState <- func(s *bState) { b.completed <- s.completed }: | |
| 291 | return <-b.completed | |
| 287 | result := make(chan bool) | |
| 288 | select { | |
| 289 | case b.operateState <- func(s *bState) { result <- s.completed }: | |
| 290 | return <-result | |
| 292 | 291 | case <-b.done: |
| 293 | 292 | return true |
| 294 | 293 | } |