Thanks Ian,

it is nice to know that there is at least "an escape hatch" through reflect 
package if needed.

Is there an upper bound for how many items could be in that slice (select 
statement)? 

Andrey

On Friday, September 13, 2019 at 12:02:18 AM UTC-6, Ian Lance Taylor wrote:
>
> On Thu, Sep 12, 2019 at 9:40 PM Andrey Tcherepanov 
> <xnow4f...@sneakemail.com <javascript:>> wrote: 
> > 
> > well, subj - why can't I "just"  do a select on a slice of channels? 
> Yes, I can run a bunch goroutines with of reads on an each channel, funnel 
> it all into 1 notification channel, pick up on the other side...  boring 
> stuff, really... 
> > 
> > But why not  "just" 
> > 
> > func main() { 
> > 
> >     cc := make([]chan interface{}, 10) 
> > 
> >     for i := 0; i < len(cc); i++ { 
> >         cc[i] = make(chan interface{}) 
> >     } 
> > 
> >     dd := make([]chan int) 
> > 
> >     for i := 0; i < 1000; i++ { 
> >         dd = append(dd, make(chan int)) 
> >     } 
> > 
> >  select { 
> > 
> >    // do we need a special <-[] ? 
> >    case i, c, v, ok := <-[]cc: 
> >       fmt.Printf("cc replied : channel index %d, channel %v, value %v, 
> ok=%v", i, c, v, ok) 
> > 
> > 
> >    // or I dunno, not introducing a new op 
> >    case i, d, v, ok := <-dd: 
> >       fmt.Printf("dd sent something: channel index %d, channel %v, value 
> %v, ok=%v", i, d, v, ok) 
> >  } 
> > 
> >  // or shorter, but I hope you get the drift 
> > 
> >  select { 
> >    case i, c, ok := <-[]cc: 
> >       fmt.Printf("cc replied : channel index %d, channel %v, value %v, 
> ok=%v", i, c, <-c, ok) 
> > 
> > 
> >    case i, d, ok := <-dd: 
> >       fmt.Printf("dd sent something: channel index %d, channel %v, value 
> %v, ok=%v", i, d, <-d, ok) 
> >  } 
> > } 
> > 
> > 
> > Why? System limitations? Rarely needed? 
> > 
> > Feels like extending language to handle that would not be too much of 
> violation of an existing code. Ok, lets go nuts! Mirrored "cc <- value" for 
> sending to a slice of channels! -- it should pick randomly available 
> channel out of the slice of channels! 
>
> You actually can do it using the reflect package: 
> https://golang.org/pkg/reflect/#Select (not because we necessarily 
> want the reflect package to support selecting on a slice of channels, 
> but because there is no other reasonable way to write reflect.Select). 
>
> It's not in the language proper mainly because it doesn't seem to come 
> up very much.  I don't think there is even a proposal for it.  And 
> while anyone is welcome to write a proposal, it will need some 
> justification for why it will be worth the cost of complicating the 
> language. 
>
> 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/dba53021-9dd4-4607-870e-2a2a0a134775%40googlegroups.com.

Reply via email to