Hacker News new | ask | show | jobs
by mw42 3666 days 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)
1 comments

Ah! Can't believe I missed that..