Keyword

Go chan keyword

Forms channel types for typed communication. A bidirectional channel supports send and receive; directional types restrict operations. A nil channel blocks ordinary sends and receives indefinitely. Example sends then receives 8 through a buffered channel.

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)  ch <- 8  var receive <-chan int = ch  fmt.Println(<-receive)}
Go Reference