3 ms·
> It'll be interesting to see if source/sink channel types ever get retrofitted to Go in a decade or so. Channels can be designated as receive-only or send-onl
by mw42 10y ago
> It'll be interesting to see if source/sink channel types ever get retrofitted to Go in a decade or so.
Channels can be designated as receive-only or send-only in variable and function declarations:
ch := make(chan int, 1)
var send chan<- int = ch
var recv <-chan int = ch
send <- 1 // ok
<- recv // ok
recv <- 1 // invalid operation: recv <- 1 (send to receive-only type <-chan int)
<- send // invalid operation: <-send (receive from send-only type chan<- int)
- akkartik 10y agoAh! Can't believe I missed that..