how to select for input on a dynamic list of channels in Go?

Go has a mechanism to do a blocking read from one of several channels, the select statement. So you can say

select {
    case <- c1:
    case <- c2:
}

will block until we get input from either of these two channels. Very nice.

But this requires that I specify in the source code how many channels I want to poll. What if I have a slice or array of channels and I want to block until I get input on any of them?

8
задан Denys Séguret 13 September 2012 в 16:24
поделиться