add bool param to newProxyReader, rather than keeping it at bar instance
Vladimir Bauer
3 years ago
| 18 | 18 |
type Bar struct {
|
| 19 | 19 |
index int // used by heap
|
| 20 | 20 |
priority int // used by heap
|
| 21 | |
hasEwma bool
|
| 22 | 21 |
frameCh chan *renderFrame
|
| 23 | 22 |
operateState chan func(*bState)
|
| 24 | 23 |
done chan struct{}
|
|
| 72 | 71 |
|
| 73 | 72 |
bar := &Bar{
|
| 74 | 73 |
priority: bs.priority,
|
| 75 | |
hasEwma: len(bs.ewmaDecorators) != 0,
|
| 76 | 74 |
frameCh: make(chan *renderFrame, 1),
|
| 77 | 75 |
operateState: make(chan func(*bState)),
|
| 78 | 76 |
done: make(chan struct{}),
|
|
| 93 | 91 |
if r == nil {
|
| 94 | 92 |
panic("expected non nil io.Reader")
|
| 95 | 93 |
}
|
| 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)
|
| 97 | 98 |
case <-b.done:
|
| 98 | 99 |
return nil
|
| 99 | |
default:
|
| 100 | |
return b.newProxyReader(r)
|
| 101 | 100 |
}
|
| 102 | 101 |
}
|
| 103 | 102 |
|
| 53 | 53 |
return n, err
|
| 54 | 54 |
}
|
| 55 | 55 |
|
| 56 | |
func (b *Bar) newProxyReader(r io.Reader) (rc io.ReadCloser) {
|
|
56 |
func (b *Bar) newProxyReader(r io.Reader, hasEwma bool) (rc io.ReadCloser) {
|
| 57 | 57 |
pr := proxyReader{toReadCloser(r), b}
|
| 58 | 58 |
if wt, ok := r.(io.WriterTo); ok {
|
| 59 | 59 |
pw := proxyWriterTo{pr, wt}
|
| 60 | |
if b.hasEwma {
|
|
60 |
if hasEwma {
|
| 61 | 61 |
rc = ewmaProxyWriterTo{ewmaProxyReader{pr}, pw}
|
| 62 | 62 |
} else {
|
| 63 | 63 |
rc = pw
|
| 64 | 64 |
}
|
| 65 | |
} else if b.hasEwma {
|
|
65 |
} else if hasEwma {
|
| 66 | 66 |
rc = ewmaProxyReader{pr}
|
| 67 | 67 |
} else {
|
| 68 | 68 |
rc = pr
|