Codebase list golang-github-vbauerster-mpb / 5c3a5ab
add bool param to newProxyReader, rather than keeping it at bar instance Vladimir Bauer 3 years ago
2 changed file(s) with 7 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
1818 type Bar struct {
1919 index int // used by heap
2020 priority int // used by heap
21 hasEwma bool
2221 frameCh chan *renderFrame
2322 operateState chan func(*bState)
2423 done chan struct{}
7271
7372 bar := &Bar{
7473 priority: bs.priority,
75 hasEwma: len(bs.ewmaDecorators) != 0,
7674 frameCh: make(chan *renderFrame, 1),
7775 operateState: make(chan func(*bState)),
7876 done: make(chan struct{}),
9391 if r == nil {
9492 panic("expected non nil io.Reader")
9593 }
96 select {
94 result := make(chan bool)
95 select {
96 case b.operateState <- func(s *bState) { result <- len(s.ewmaDecorators) != 0 }:
97 return b.newProxyReader(r, <-result)
9798 case <-b.done:
9899 return nil
99 default:
100 return b.newProxyReader(r)
101100 }
102101 }
103102
5353 return n, err
5454 }
5555
56 func (b *Bar) newProxyReader(r io.Reader) (rc io.ReadCloser) {
56 func (b *Bar) newProxyReader(r io.Reader, hasEwma bool) (rc io.ReadCloser) {
5757 pr := proxyReader{toReadCloser(r), b}
5858 if wt, ok := r.(io.WriterTo); ok {
5959 pw := proxyWriterTo{pr, wt}
60 if b.hasEwma {
60 if hasEwma {
6161 rc = ewmaProxyWriterTo{ewmaProxyReader{pr}, pw}
6262 } else {
6363 rc = pw
6464 }
65 } else if b.hasEwma {
65 } else if hasEwma {
6666 rc = ewmaProxyReader{pr}
6767 } else {
6868 rc = pr