wrap waitgroup around every function call
This commit is contained in:
parent
9b57621ecd
commit
b5d6b4541a
|
@ -21,7 +21,6 @@ var afunc funcWait
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
|
|
||||||
func generateNumbers(total int, ch chan<- *funcWait, af *funcWait) {
|
func generateNumbers(total int, ch chan<- *funcWait, af *funcWait) {
|
||||||
|
|
||||||
log.Println("generateNumbers() START total =", total)
|
log.Println("generateNumbers() START total =", total)
|
||||||
ch <- af
|
ch <- af
|
||||||
log.Println("generateNumbers() END total =", total)
|
log.Println("generateNumbers() END total =", total)
|
||||||
|
@ -34,6 +33,7 @@ func andlabsGoroutine(ch <-chan *funcWait, wg *sync.WaitGroup) {
|
||||||
for f := range ch {
|
for f := range ch {
|
||||||
log.Println("andlabsGoroutine() read f() from channel")
|
log.Println("andlabsGoroutine() read f() from channel")
|
||||||
f.f()
|
f.f()
|
||||||
|
f.wgF.Done()
|
||||||
}
|
}
|
||||||
log.Printf("andlabsGoroutine() END")
|
log.Printf("andlabsGoroutine() END")
|
||||||
}
|
}
|
||||||
|
@ -54,8 +54,12 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
for idx := 1; idx <= 10; idx++ {
|
for idx := 1; idx <= 10; idx++ {
|
||||||
|
log.Println("START waitgroup idx =", idx)
|
||||||
afunc.val = idx * 20
|
afunc.val = idx * 20
|
||||||
|
afunc.wgF.Add(1)
|
||||||
generateNumbers(idx, functionChan, &afunc)
|
generateNumbers(idx, functionChan, &afunc)
|
||||||
|
afunc.wgF.Wait()
|
||||||
|
log.Println("END waitgroup idx =", idx)
|
||||||
}
|
}
|
||||||
wg.Done()
|
wg.Done()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue