diff --git a/bar.go b/bar.go index d18c7f4..218988a 100644 --- a/bar.go +++ b/bar.go @@ -19,7 +19,6 @@ type Bar struct { index int // used by heap priority int // used by heap - hasEwma bool frameCh chan *renderFrame operateState chan func(*bState) done chan struct{} @@ -73,7 +72,6 @@ bar := &Bar{ priority: bs.priority, - hasEwma: len(bs.ewmaDecorators) != 0, frameCh: make(chan *renderFrame, 1), operateState: make(chan func(*bState)), done: make(chan struct{}), @@ -94,11 +92,12 @@ if r == nil { panic("expected non nil io.Reader") } - select { + result := make(chan bool) + select { + case b.operateState <- func(s *bState) { result <- len(s.ewmaDecorators) != 0 }: + return b.newProxyReader(r, <-result) case <-b.done: return nil - default: - return b.newProxyReader(r) } } diff --git a/proxyreader.go b/proxyreader.go index 51b63ea..193ef0a 100644 --- a/proxyreader.go +++ b/proxyreader.go @@ -54,16 +54,16 @@ return n, err } -func (b *Bar) newProxyReader(r io.Reader) (rc io.ReadCloser) { +func (b *Bar) newProxyReader(r io.Reader, hasEwma bool) (rc io.ReadCloser) { pr := proxyReader{toReadCloser(r), b} if wt, ok := r.(io.WriterTo); ok { pw := proxyWriterTo{pr, wt} - if b.hasEwma { + if hasEwma { rc = ewmaProxyWriterTo{ewmaProxyReader{pr}, pw} } else { rc = pw } - } else if b.hasEwma { + } else if hasEwma { rc = ewmaProxyReader{pr} } else { rc = pr