Skip to content

Commit 6b48433

Browse files
committed
refactoring io example
1 parent fd60cdd commit 6b48433

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

_examples/io/main.go

+13-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,17 @@ import (
1111
)
1212

1313
func main() {
14-
var total int64 = 1024 * 1024 * 500
15-
reader := io.LimitReader(rand.Reader, total)
14+
var total int64 = 64 * 1024 * 1024
15+
16+
r, w := io.Pipe()
17+
18+
go func() {
19+
for i := 0; i < 1024; i++ {
20+
_, _ = io.Copy(w, io.LimitReader(rand.Reader, 64*1024))
21+
time.Sleep(time.Second / 10)
22+
}
23+
w.Close()
24+
}()
1625

1726
p := mpb.New(
1827
mpb.WithWidth(60),
@@ -27,12 +36,12 @@ func main() {
2736
mpb.AppendDecorators(
2837
decor.EwmaETA(decor.ET_STYLE_GO, 30),
2938
decor.Name(" ] "),
30-
decor.EwmaSpeed(decor.SizeB1024(0), "% .2f", 30),
39+
decor.EwmaSpeed(decor.SizeB1024(0), "% .2f", 60),
3140
),
3241
)
3342

3443
// create proxy reader
35-
proxyReader := bar.ProxyReader(reader)
44+
proxyReader := bar.ProxyReader(r)
3645
defer proxyReader.Close()
3746

3847
// copy from proxyReader, ignoring errors

0 commit comments

Comments
 (0)