Codebase list golang-github-vbauerster-mpb / d2ecb20
unify wg comments across all examples Vladimir Bauer 4 years ago
14 changed file(s) with 33 addition(s) and 26 deletion(s). Raw diff Collapse all Expand all
6464
6565 ```go
6666 var wg sync.WaitGroup
67 // passed &wg will be accounted at p.Wait() call
67 // passed wg will be accounted at p.Wait() call
6868 p := mpb.New(mpb.WithWaitGroup(&wg))
6969 total, numBars := 100, 3
7070 wg.Add(numBars)
102102 }
103103 }()
104104 }
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
106106 p.Wait()
107107 ```
108108
1212
1313 func main() {
1414 var wg sync.WaitGroup
15 // passed wg will be accounted at p.Wait() call
1516 p := mpb.New(mpb.WithWaitGroup(&wg))
1617 total, numBars := 100, 3
1718 wg.Add(numBars)
5455 }
5556 }()
5657 }
57 // wait for all bars to complete and flush
58 // wait for passed wg and for all bars to complete and flush
5859 p.Wait()
5960 }
1515 defer cancel()
1616
1717 var wg sync.WaitGroup
18 // passed wg will be accounted at p.Wait() call
1819 p := mpb.NewWithContext(ctx, mpb.WithWaitGroup(&wg))
1920 total := 300
2021 numBars := 3
4849 }
4950 }()
5051 }
51
52 // wait for passed wg and for all bars to complete and flush
5253 p.Wait()
5354 }
1515
1616 func main() {
1717 doneWg := new(sync.WaitGroup)
18 // passed doneWg will be accounted at p.Wait() call
1819 p := mpb.New(mpb.WithWaitGroup(doneWg))
1920 numBars := 4
2021
6364 go newTask(doneWg, b, numBars-i)
6465 }()
6566 }
66
67 // wait for passed doneWg and for all bars to complete and flush
6768 p.Wait()
6869 }
6970
1111
1212 func main() {
1313 var wg sync.WaitGroup
14 // passed wg will be accounted at p.Wait() call
1415 p := mpb.New(
1516 mpb.WithWaitGroup(&wg),
16 // container's width.
1717 mpb.WithWidth(60),
1818 )
1919 total, numBars := 100, 3
5454 }
5555 }()
5656 }
57 // wait for all bars to complete and flush
57 // wait for passed wg and for all bars to complete and flush
5858 p.Wait()
5959 }
1111
1212 func main() {
1313 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
1515 p := mpb.New(mpb.WithWaitGroup(&wg), mpb.WithWidth(60))
1616 total, numBars := 100, 3
1717 wg.Add(numBars)
5858 }
5959 }()
6060 }
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
6262 p.Wait()
6363 }
6464
1111
1212 func main() {
1313 var wg sync.WaitGroup
14 // passed &wg will be accounted at p.Wait() call
14 // passed wg will be accounted at p.Wait() call
1515 p := mpb.New(mpb.WithWaitGroup(&wg))
1616 total, numBars := 100, 3
1717 wg.Add(numBars)
4949 }
5050 }()
5151 }
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
5353 p.Wait()
5454 }
1212
1313 func main() {
1414 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 )
1620
1721 wantPanic := strings.Repeat("Panic ", 64)
1822 numBars := 3
3034 }
3135 }()
3236 }
33
37 // wait for passed wg and for all bars to complete and flush
3438 p.Wait()
3539 }
3640
1919 func main() {
2020 flag.Parse()
2121 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
2323 p := mpb.New(
2424 mpb.WithWaitGroup(&wg),
2525 mpb.ContainerOptional(
6767 }
6868 }()
6969 }
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
7171 p.Wait()
7272 fmt.Println("done")
7373 }
1111
1212 func main() {
1313 var wg sync.WaitGroup
14 // passed wg will be accounted at p.Wait() call
1415 p := mpb.New(mpb.WithWaitGroup(&wg))
1516 total := 100
1617 numBars := 3
4849 }
4950 }()
5051 }
51
52 // wait for passed wg and for all bars to complete and flush
5253 p.Wait()
5354 }
1111
1212 func main() {
1313 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))
1816 total, numBars := 100, 3
1917 wg.Add(numBars)
2018
5149 }
5250 }()
5351 }
54 // wait for all bars to complete and flush
52 // wait for passed wg and for all bars to complete and flush
5553 p.Wait()
5654 }
5755
1111
1212 func main() {
1313 var wg sync.WaitGroup
14 // passed wg will be accounted at p.Wait() call
1415 p := mpb.New(
15 // passing &wg will make p.Wait() call wait for it first
1616 mpb.WithWaitGroup(&wg),
1717 mpb.WithWidth(16),
1818 )
5050 }
5151 }()
5252 }
53 // wait for all bars to complete and flush
53 // wait for passed wg and for all bars to complete and flush
5454 p.Wait()
5555 }
5656
1111
1212 func main() {
1313 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
1515 p := mpb.New(mpb.WithWaitGroup(&wg), mpb.WithWidth(64))
1616 total, numBars := 100, 3
1717 wg.Add(numBars)
4343 }
4444 }()
4545 }
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
4747 p.Wait()
4848 }
1515
1616 func main() {
1717 var wg sync.WaitGroup
18 // passed wg will be accounted at p.Wait() call
1819 p := mpb.New(mpb.WithWaitGroup(&wg))
1920 wg.Add(totalBars)
2021
4344 }
4445 }()
4546 }
46
47 // wait for passed wg and for all bars to complete and flush
4748 p.Wait()
4849 }