Reputation: 473
I'd like to send a pointer to a channel through a channel. Is it possible in Go? How to define function that accepts such channel?
I tried:
func test() (chan *chan)
func test() (chan chan)
Upvotes: 3
Views: 1626
Reputation: 120941
There is always some type associated with a channel. Let's assume that the type is T
. A channel of T is:
chan T
A pointer to a channel of T is:
*chan T
A channel of pointer to channel of T is:
chan *chan T
A function accepting the channel of pointer to channel of T is:
func f(c chan *chan T) { }
Because channels are reference types, you probably don't need to use a pointer. Try using
func (f c chan chan T) { }
Upvotes: 10