Codebase list golang-github-vbauerster-mpb / 123c1a2
don't embed time.Now() value inside ewmaProxy... Vladimir Bauer 4 years ago
1 changed file(s) with 6 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
3737 type ewmaProxyReader struct {
3838 io.ReadCloser // *proxyReader
3939 bar *Bar
40 iT time.Time
4140 }
4241
4342 func (x *ewmaProxyReader) Read(p []byte) (int, error) {
43 start := time.Now()
4444 n, err := x.ReadCloser.Read(p)
4545 if n > 0 {
46 x.bar.DecoratorEwmaUpdate(time.Since(x.iT))
47 x.iT = time.Now()
46 x.bar.DecoratorEwmaUpdate(time.Since(start))
4847 }
4948 return n, err
5049 }
5352 io.ReadCloser // *ewmaProxyReader
5453 wt io.WriterTo // *proxyWriterTo
5554 bar *Bar
56 iT time.Time
5755 }
5856
5957 func (x *ewmaProxyWriterTo) WriteTo(w io.Writer) (int64, error) {
58 start := time.Now()
6059 n, err := x.wt.WriteTo(w)
6160 if n > 0 {
62 x.bar.DecoratorEwmaUpdate(time.Since(x.iT))
63 x.iT = time.Now()
61 x.bar.DecoratorEwmaUpdate(time.Since(start))
6462 }
6563 return n, err
6664 }
7068 rc = &proxyReader{rc, bar}
7169
7270 if wt, isWriterTo := r.(io.WriterTo); bar.hasEwmaDecorators {
73 now := time.Now()
74 rc = &ewmaProxyReader{rc, bar, now}
71 rc = &ewmaProxyReader{rc, bar}
7572 if isWriterTo {
76 rc = &ewmaProxyWriterTo{rc, wt, bar, now}
73 rc = &ewmaProxyWriterTo{rc, wt, bar}
7774 }
7875 } else if isWriterTo {
7976 rc = &proxyWriterTo{rc, wt, bar}