Channels
Context
Section titled “Context”Channels are typed conduits that allow goroutines to communicate and synchronize. You send a value into a channel using ch <- v and receive a value using v := <-ch. By default, channels are unbuffered: sends block until a receiver is ready, and vice versa.
Example
Section titled “Example”Create a channel and pass a value between two goroutines.
Code example
Section titled “Code example”package main
import "fmt"
func main() { ch := make(chan string)
go func() { ch <- "ping" }()
msg := <-ch fmt.Println(msg)}Output
Section titled “Output”ping