https://play.golang.org/p/5KwJQcTsUPg

I fixed it.

The code you have written there has weird non-standard utf-8 code points in 
it. It won't make any difference whether you defer the Wait() if no Add is 
called the goroutine does not start now.

On Sunday, 5 May 2019 12:27:10 UTC+2, Jan Mercl wrote:
>
> On Sun, May 5, 2019 at 12:06 PM Louki Sumirniy 
> <louki.sumi...@gmail.com <javascript:>> wrote: 
>
> > Is there ANY other use case for waitgroup other than preventing a 
> goroutine leak or ensuring that it empties the channels at the end of 
> execution? 
>
> I don't think this question is related to the correctness of your 
> shorter implementation of WaitGroup. Anyway, what about such code? 
>
>         var wg sync.WaitGroup 
>
>         func main() { 
>                 defer wg.Wait() 
>
>                 if someCondition { 
>                         for i := 0; i < 4; i++ { 
>                                 wg.Add(1) 
>                                 go worker(i) 
>                         } 
>                 } 
>                 ... 
>         } 
>
>         func worker(i int) { 
>                 defer wg.Done() 
>
>                 ... 
>         } 
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to