diff --git a/bar.go b/bar.go index 8f4e58f..03e7518 100644 --- a/bar.go +++ b/bar.go @@ -90,14 +90,7 @@ if r == nil { panic("expected non nil io.Reader") } - result := make(chan bool) - select { - case b.operateState <- func(s *bState) { result <- s.triggerComplete }: - triggerComplete := <-result - return b.newProxyReader(r, !triggerComplete) - case <-b.done: - return nil - } + return b.newProxyReader(r) } // ID returs id of the bar. diff --git a/proxyreader.go b/proxyreader.go index c9a14b0..582a55e 100644 --- a/proxyreader.go +++ b/proxyreader.go @@ -8,14 +8,13 @@ type proxyReader struct { io.ReadCloser - bar *Bar - totalUnknown bool + bar *Bar } func (x proxyReader) Read(p []byte) (int, error) { n, err := x.ReadCloser.Read(p) x.bar.IncrBy(n) - if x.totalUnknown && err == io.EOF { + if err == io.EOF { go x.bar.SetTotal(-1, true) } return n, err @@ -29,7 +28,7 @@ func (x proxyWriterTo) WriteTo(w io.Writer) (int64, error) { n, err := x.wt.WriteTo(w) x.bar.IncrInt64(n) - if x.totalUnknown && err == io.EOF { + if err == io.EOF { go x.bar.SetTotal(-1, true) } return n, err @@ -62,8 +61,8 @@ return n, err } -func (b *Bar) newProxyReader(r io.Reader, totalUnknown bool) (rc io.ReadCloser) { - pr := proxyReader{toReadCloser(r), b, totalUnknown} +func (b *Bar) newProxyReader(r io.Reader) (rc io.ReadCloser) { + pr := proxyReader{toReadCloser(r), b} if wt, ok := r.(io.WriterTo); ok { pw := proxyWriterTo{pr, wt} if b.hasEwma {