1. your generator never finished
2. your work channel still has things in it, there's no guarantee select
will choose done first
3. reading from a closed channel will give you a zero value


On Mon, Mar 28, 2022, 16:53 Gowtham Raj <rgowtham...@gmail.com> wrote:

> In this example, we have a *worker*. The idea here is simulate clean
> shutdown of all go routines based on a condition.
>
> In this case, go routines get spun - based on workers count. Each go
> routine reads the channel, does some work and sends output to the
> outputChannel.
>
> The main go routine reads this output and prints it. To simulate a stop
> condition, the doneChannel is closed. Expected outcome is that select inside
> each go routine will pick this up and execute return which in turn will
> call the defer println. The actual output is that it never gets called
> and main exits.
>
> Not sure what's the reason behind this.
>
> Code at *https://go.dev/play/p/-R7Llw9X_6U
> <https://go.dev/play/p/-R7Llw9X_6U> *
>
> Can you please help to figure out the bug in this code.
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/3762b074-63c5-407e-9515-6833465dc94en%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/3762b074-63c5-407e-9515-6833465dc94en%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAGabyPoU1ZXAi0TiURXgODR%3DEGXnwLyhO0u59R1yv2jfJrc%3DDw%40mail.gmail.com.

Reply via email to