On Fri, Jan 24, 2020 at 4:25 AM Prabhu Chawandi
<prabhu.s.chawa...@gmail.com> wrote:
>
>  I have n routines launched before reaching this select statement.
> From the routine it will fetch response from upstream server and write it to 
> channel.
>
> When wait count reaches  zero,  first case will be hit. I see only one 
> response being read, even if 10 other go routines have written to channel. 
> Shall I use range to go over rest of the contents, like below? or any other 
> way is there?
>
> https://play.golang.org/p/kfHauJJHFtz
>
>  select {
>  case v := <-stop:
>   fmt.Println(v)
>   for v1 := range stop {
>    fmt.Println(v1)
>   }
>  }


I'm sorry, I don't understand what you are asking.  Thanks for
providing a playground link.  That program works as I would expect.
Perhaps you could explain what you expect it to do that is different
from what it actually does.

A single receive from a channel, as in "v := <-stop" above, will read
a single value from the channel.  If you want to read more than one
value from a channel, you do need to use a loop, as your program does.

Ian

-- 
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/CAOyqgcXEdN7vSNFiSYbvmCuc6rORJ3H6Q5u7XVAdOm08rcdGJw%40mail.gmail.com.

Reply via email to