Ahaha! you made a race, actually! I mean I made a race, but that code exposed it.
I'm gonna just go away for a while. My brain doesn't really seem to be keen on doing this kind of thinking right at this minute. On Sunday, 5 May 2019 12:54:25 UTC+2, Louki Sumirniy wrote: > > hang on, sorry to be so chatty on this but I'm learning a lot about > handling edge cases from this, so I need to comment further > > ok, I got it working for that test also: > > https://play.golang.org/p/nd_EuCSOWto > > I can tell by the fact you used the 'sync' keyword that you didn't in fact > test what you wrote, but the above completes the code and shows the > condition is handled. > > 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> 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.