Type system

Go channel types

Typed communication endpoints; direction limits sends and receives. A nil channel cannot proceed with a send or receive. Example output: '4'.

Formal Syntax & Structure

go syntaxgo
chan T; chan<- T; <-chan T

Working Example

Example Snippetgo
package main
import (  "fmt")
func main() {  ch := make(chan int, 1)  var send chan<- int = ch  var recv <-chan int = ch  send <- 4  fmt.Println(<-recv)}
Go Reference