File tree 1 file changed +10
-9
lines changed
_examples/progressAsWriter
1 file changed +10
-9
lines changed Original file line number Diff line number Diff line change @@ -13,16 +13,13 @@ import (
13
13
14
14
func main () {
15
15
total , numBars := 100 , 2
16
- var wg sync.WaitGroup
17
- wg .Add (numBars )
16
+ var bwg sync.WaitGroup
17
+ bwg .Add (numBars )
18
18
done := make (chan interface {})
19
- p := mpb .New (
20
- mpb .WithWidth (64 ),
21
- mpb .WithWaitGroup (& wg ),
22
- mpb .WithShutdownNotifier (done ),
23
- )
19
+ p := mpb .New (mpb .WithWidth (64 ), mpb .WithShutdownNotifier (done ))
24
20
25
21
log .SetOutput (p )
22
+ nopBar := p .MustAdd (0 , nil )
26
23
27
24
for i := 0 ; i < numBars ; i ++ {
28
25
name := fmt .Sprintf ("Bar#%d:" , i )
@@ -39,7 +36,7 @@ func main() {
39
36
)
40
37
// simulating some work
41
38
go func () {
42
- defer wg .Done ()
39
+ defer bwg .Done ()
43
40
rng := rand .New (rand .NewSource (time .Now ().UnixNano ()))
44
41
max := 100 * time .Millisecond
45
42
for i := 0 ; i < total ; i ++ {
@@ -67,12 +64,16 @@ func main() {
67
64
break quit
68
65
default :
69
66
log .Println ("waiting for done" )
70
- time .Sleep (100 * time .Millisecond )
67
+ time .Sleep (150 * time .Millisecond )
71
68
}
72
69
}
73
70
qwg .Done ()
74
71
}()
75
72
73
+ bwg .Wait ()
74
+ log .Println ("completing nop bar" )
75
+ nopBar .EnableTriggerComplete ()
76
+
76
77
p .Wait ()
77
78
qwg .Wait ()
78
79
}
You can’t perform that action at this time.
0 commit comments