unify wg comments across all examples
Vladimir Bauer
4 years ago
| 64 | 64 |
|
| 65 | 65 |
```go
|
| 66 | 66 |
var wg sync.WaitGroup
|
| 67 | |
// passed &wg will be accounted at p.Wait() call
|
|
67 |
// passed wg will be accounted at p.Wait() call
|
| 68 | 68 |
p := mpb.New(mpb.WithWaitGroup(&wg))
|
| 69 | 69 |
total, numBars := 100, 3
|
| 70 | 70 |
wg.Add(numBars)
|
|
| 102 | 102 |
}
|
| 103 | 103 |
}()
|
| 104 | 104 |
}
|
| 105 | |
// Waiting for passed &wg and for all bars to complete and flush
|
|
105 |
// wait for passed wg and for all bars to complete and flush
|
| 106 | 106 |
p.Wait()
|
| 107 | 107 |
```
|
| 108 | 108 |
|
| 12 | 12 |
|
| 13 | 13 |
func main() {
|
| 14 | 14 |
var wg sync.WaitGroup
|
|
15 |
// passed wg will be accounted at p.Wait() call
|
| 15 | 16 |
p := mpb.New(mpb.WithWaitGroup(&wg))
|
| 16 | 17 |
total, numBars := 100, 3
|
| 17 | 18 |
wg.Add(numBars)
|
|
| 54 | 55 |
}
|
| 55 | 56 |
}()
|
| 56 | 57 |
}
|
| 57 | |
// wait for all bars to complete and flush
|
|
58 |
// wait for passed wg and for all bars to complete and flush
|
| 58 | 59 |
p.Wait()
|
| 59 | 60 |
}
|
| 15 | 15 |
defer cancel()
|
| 16 | 16 |
|
| 17 | 17 |
var wg sync.WaitGroup
|
|
18 |
// passed wg will be accounted at p.Wait() call
|
| 18 | 19 |
p := mpb.NewWithContext(ctx, mpb.WithWaitGroup(&wg))
|
| 19 | 20 |
total := 300
|
| 20 | 21 |
numBars := 3
|
|
| 48 | 49 |
}
|
| 49 | 50 |
}()
|
| 50 | 51 |
}
|
| 51 | |
|
|
52 |
// wait for passed wg and for all bars to complete and flush
|
| 52 | 53 |
p.Wait()
|
| 53 | 54 |
}
|
| 15 | 15 |
|
| 16 | 16 |
func main() {
|
| 17 | 17 |
doneWg := new(sync.WaitGroup)
|
|
18 |
// passed doneWg will be accounted at p.Wait() call
|
| 18 | 19 |
p := mpb.New(mpb.WithWaitGroup(doneWg))
|
| 19 | 20 |
numBars := 4
|
| 20 | 21 |
|
|
| 63 | 64 |
go newTask(doneWg, b, numBars-i)
|
| 64 | 65 |
}()
|
| 65 | 66 |
}
|
| 66 | |
|
|
67 |
// wait for passed doneWg and for all bars to complete and flush
|
| 67 | 68 |
p.Wait()
|
| 68 | 69 |
}
|
| 69 | 70 |
|
| 11 | 11 |
|
| 12 | 12 |
func main() {
|
| 13 | 13 |
var wg sync.WaitGroup
|
|
14 |
// passed wg will be accounted at p.Wait() call
|
| 14 | 15 |
p := mpb.New(
|
| 15 | 16 |
mpb.WithWaitGroup(&wg),
|
| 16 | |
// container's width.
|
| 17 | 17 |
mpb.WithWidth(60),
|
| 18 | 18 |
)
|
| 19 | 19 |
total, numBars := 100, 3
|
|
| 54 | 54 |
}
|
| 55 | 55 |
}()
|
| 56 | 56 |
}
|
| 57 | |
// wait for all bars to complete and flush
|
|
57 |
// wait for passed wg and for all bars to complete and flush
|
| 58 | 58 |
p.Wait()
|
| 59 | 59 |
}
|
| 11 | 11 |
|
| 12 | 12 |
func main() {
|
| 13 | 13 |
var wg sync.WaitGroup
|
| 14 | |
// pass &wg (optional), so p will wait for it eventually
|
|
14 |
// passed wg will be accounted at p.Wait() call
|
| 15 | 15 |
p := mpb.New(mpb.WithWaitGroup(&wg), mpb.WithWidth(60))
|
| 16 | 16 |
total, numBars := 100, 3
|
| 17 | 17 |
wg.Add(numBars)
|
|
| 58 | 58 |
}
|
| 59 | 59 |
}()
|
| 60 | 60 |
}
|
| 61 | |
// Waiting for passed &wg and for all bars to complete and flush
|
|
61 |
// wait for passed wg and for all bars to complete and flush
|
| 62 | 62 |
p.Wait()
|
| 63 | 63 |
}
|
| 64 | 64 |
|
| 11 | 11 |
|
| 12 | 12 |
func main() {
|
| 13 | 13 |
var wg sync.WaitGroup
|
| 14 | |
// passed &wg will be accounted at p.Wait() call
|
|
14 |
// passed wg will be accounted at p.Wait() call
|
| 15 | 15 |
p := mpb.New(mpb.WithWaitGroup(&wg))
|
| 16 | 16 |
total, numBars := 100, 3
|
| 17 | 17 |
wg.Add(numBars)
|
|
| 49 | 49 |
}
|
| 50 | 50 |
}()
|
| 51 | 51 |
}
|
| 52 | |
// Waiting for passed &wg and for all bars to complete and flush
|
|
52 |
// wait for passed wg and for all bars to complete and flush
|
| 53 | 53 |
p.Wait()
|
| 54 | 54 |
}
|
| 12 | 12 |
|
| 13 | 13 |
func main() {
|
| 14 | 14 |
var wg sync.WaitGroup
|
| 15 | |
p := mpb.New(mpb.WithWaitGroup(&wg), mpb.WithDebugOutput(os.Stderr))
|
|
15 |
// passed wg will be accounted at p.Wait() call
|
|
16 |
p := mpb.New(
|
|
17 |
mpb.WithWaitGroup(&wg),
|
|
18 |
mpb.WithDebugOutput(os.Stderr),
|
|
19 |
)
|
| 16 | 20 |
|
| 17 | 21 |
wantPanic := strings.Repeat("Panic ", 64)
|
| 18 | 22 |
numBars := 3
|
|
| 30 | 34 |
}
|
| 31 | 35 |
}()
|
| 32 | 36 |
}
|
| 33 | |
|
|
37 |
// wait for passed wg and for all bars to complete and flush
|
| 34 | 38 |
p.Wait()
|
| 35 | 39 |
}
|
| 36 | 40 |
|
| 19 | 19 |
func main() {
|
| 20 | 20 |
flag.Parse()
|
| 21 | 21 |
var wg sync.WaitGroup
|
| 22 | |
// pass &wg (optional), so p will wait for it eventually
|
|
22 |
// passed wg will be accounted at p.Wait() call
|
| 23 | 23 |
p := mpb.New(
|
| 24 | 24 |
mpb.WithWaitGroup(&wg),
|
| 25 | 25 |
mpb.ContainerOptional(
|
|
| 67 | 67 |
}
|
| 68 | 68 |
}()
|
| 69 | 69 |
}
|
| 70 | |
// Waiting for passed &wg and for all bars to complete and flush
|
|
70 |
// wait for passed wg and for all bars to complete and flush
|
| 71 | 71 |
p.Wait()
|
| 72 | 72 |
fmt.Println("done")
|
| 73 | 73 |
}
|
| 11 | 11 |
|
| 12 | 12 |
func main() {
|
| 13 | 13 |
var wg sync.WaitGroup
|
|
14 |
// passed wg will be accounted at p.Wait() call
|
| 14 | 15 |
p := mpb.New(mpb.WithWaitGroup(&wg))
|
| 15 | 16 |
total := 100
|
| 16 | 17 |
numBars := 3
|
|
| 48 | 49 |
}
|
| 49 | 50 |
}()
|
| 50 | 51 |
}
|
| 51 | |
|
|
52 |
// wait for passed wg and for all bars to complete and flush
|
| 52 | 53 |
p.Wait()
|
| 53 | 54 |
}
|
| 11 | 11 |
|
| 12 | 12 |
func main() {
|
| 13 | 13 |
var wg sync.WaitGroup
|
| 14 | |
p := mpb.New(
|
| 15 | |
// passing &wg will make p.Wait() call wait for it first
|
| 16 | |
mpb.WithWaitGroup(&wg),
|
| 17 | |
)
|
|
14 |
// passed wg will be accounted at p.Wait() call
|
|
15 |
p := mpb.New(mpb.WithWaitGroup(&wg))
|
| 18 | 16 |
total, numBars := 100, 3
|
| 19 | 17 |
wg.Add(numBars)
|
| 20 | 18 |
|
|
| 51 | 49 |
}
|
| 52 | 50 |
}()
|
| 53 | 51 |
}
|
| 54 | |
// wait for all bars to complete and flush
|
|
52 |
// wait for passed wg and for all bars to complete and flush
|
| 55 | 53 |
p.Wait()
|
| 56 | 54 |
}
|
| 57 | 55 |
|
| 11 | 11 |
|
| 12 | 12 |
func main() {
|
| 13 | 13 |
var wg sync.WaitGroup
|
|
14 |
// passed wg will be accounted at p.Wait() call
|
| 14 | 15 |
p := mpb.New(
|
| 15 | |
// passing &wg will make p.Wait() call wait for it first
|
| 16 | 16 |
mpb.WithWaitGroup(&wg),
|
| 17 | 17 |
mpb.WithWidth(16),
|
| 18 | 18 |
)
|
|
| 50 | 50 |
}
|
| 51 | 51 |
}()
|
| 52 | 52 |
}
|
| 53 | |
// wait for all bars to complete and flush
|
|
53 |
// wait for passed wg and for all bars to complete and flush
|
| 54 | 54 |
p.Wait()
|
| 55 | 55 |
}
|
| 56 | 56 |
|
| 11 | 11 |
|
| 12 | 12 |
func main() {
|
| 13 | 13 |
var wg sync.WaitGroup
|
| 14 | |
// pass &wg (optional), so p will wait for it eventually
|
|
14 |
// passed wg will be accounted at p.Wait() call
|
| 15 | 15 |
p := mpb.New(mpb.WithWaitGroup(&wg), mpb.WithWidth(64))
|
| 16 | 16 |
total, numBars := 100, 3
|
| 17 | 17 |
wg.Add(numBars)
|
|
| 43 | 43 |
}
|
| 44 | 44 |
}()
|
| 45 | 45 |
}
|
| 46 | |
// Waiting for passed &wg and for all bars to complete and flush
|
|
46 |
// wait for passed wg and for all bars to complete and flush
|
| 47 | 47 |
p.Wait()
|
| 48 | 48 |
}
|
| 15 | 15 |
|
| 16 | 16 |
func main() {
|
| 17 | 17 |
var wg sync.WaitGroup
|
|
18 |
// passed wg will be accounted at p.Wait() call
|
| 18 | 19 |
p := mpb.New(mpb.WithWaitGroup(&wg))
|
| 19 | 20 |
wg.Add(totalBars)
|
| 20 | 21 |
|
|
| 43 | 44 |
}
|
| 44 | 45 |
}()
|
| 45 | 46 |
}
|
| 46 | |
|
|
47 |
// wait for passed wg and for all bars to complete and flush
|
| 47 | 48 |
p.Wait()
|
| 48 | 49 |
}
|