From b5d6b4541ac81e180cc2e0619e4dfb68ec57e6c6 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 14 Nov 2022 09:51:18 -0600 Subject: [PATCH] wrap waitgroup around every function call --- example-go-channel/sendFunction.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/example-go-channel/sendFunction.go b/example-go-channel/sendFunction.go index f66916d..fe33338 100644 --- a/example-go-channel/sendFunction.go +++ b/example-go-channel/sendFunction.go @@ -21,7 +21,6 @@ var afunc funcWait var wg sync.WaitGroup func generateNumbers(total int, ch chan<- *funcWait, af *funcWait) { - log.Println("generateNumbers() START total =", total) ch <- af log.Println("generateNumbers() END total =", total) @@ -34,6 +33,7 @@ func andlabsGoroutine(ch <-chan *funcWait, wg *sync.WaitGroup) { for f := range ch { log.Println("andlabsGoroutine() read f() from channel") f.f() + f.wgF.Done() } log.Printf("andlabsGoroutine() END") } @@ -54,8 +54,12 @@ func main() { } for idx := 1; idx <= 10; idx++ { + log.Println("START waitgroup idx =", idx) afunc.val = idx * 20 + afunc.wgF.Add(1) generateNumbers(idx, functionChan, &afunc) + afunc.wgF.Wait() + log.Println("END waitgroup idx =", idx) } wg.Done()