refactoring: interceptIO
Vladimir Bauer
3 years ago
| 25 | 25 | uwg *sync.WaitGroup |
| 26 | 26 | bwg *sync.WaitGroup |
| 27 | 27 | operateState chan func(*pState) |
| 28 | interceptIo chan func(io.Writer) | |
| 28 | interceptIO chan func(io.Writer) | |
| 29 | 29 | done chan struct{} |
| 30 | 30 | shutdown chan struct{} |
| 31 | 31 | cancel func() |
| 86 | 86 | uwg: s.uwg, |
| 87 | 87 | bwg: new(sync.WaitGroup), |
| 88 | 88 | operateState: make(chan func(*pState)), |
| 89 | interceptIo: make(chan func(io.Writer)), | |
| 89 | interceptIO: make(chan func(io.Writer)), | |
| 90 | 90 | done: make(chan struct{}), |
| 91 | 91 | shutdown: make(chan struct{}), |
| 92 | 92 | cancel: cancel, |
| 182 | 182 | } |
| 183 | 183 | ch := make(chan *result) |
| 184 | 184 | select { |
| 185 | case p.interceptIo <- func(w io.Writer) { | |
| 185 | case p.interceptIO <- func(w io.Writer) { | |
| 186 | 186 | n, err := w.Write(b) |
| 187 | 187 | ch <- &result{n, err} |
| 188 | 188 | }: |
| 253 | 253 | select { |
| 254 | 254 | case op := <-p.operateState: |
| 255 | 255 | op(s) |
| 256 | case fn := <-p.interceptIo: | |
| 256 | case fn := <-p.interceptIO: | |
| 257 | 257 | fn(cw) |
| 258 | 258 | case <-tickerC: |
| 259 | 259 | e := render() |