Re: [go-nuts] How to handle reading channels

2020-01-24 Thread Prabhu Chawandi
Thank you, you answered my question. I wanted to know whether I am right in
doing so or something else I am missing to read a channel all at once.

On Fri, Jan 24, 2020 at 8:09 PM Ian Lance Taylor  wrote:

> On Fri, Jan 24, 2020 at 4:25 AM Prabhu Chawandi
>  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/CAP3P0byVJv8Sija3xZyAK9TXUH%3DjEqPqLiGD%3Dn_iTc5Ys0-Cvw%40mail.gmail.com.


Re: [go-nuts] How to handle reading channels

2020-01-24 Thread Ian Lance Taylor
On Fri, Jan 24, 2020 at 4:25 AM Prabhu Chawandi
 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.


[go-nuts] How to handle reading channels

2020-01-24 Thread Prabhu Chawandi
Hello,

 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)
  }
 }

Thanks.

-- 
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/CAP3P0bwoknSej%3DKzJi55LziRCHkYD_6v4DL9%3D6RNUMUirURPOA%40mail.gmail.com.