Channels

A channel is a typed Go communication mechanism that allows goroutines to send and receive values. Sending and receiving can synchronize goroutines, making channels useful for transferring messages or work between concurrent parts of an application.

Minimal example

go
messages := make(chan string)
go func() {
    messages <- "order accepted"
}()
message := <-messages
fmt.Println(message)

Learn this concept

Lesson 5.1 · Channels, select and cleanup

Used in exercises

Exercise 5.3 · Per-user WebSocket hub
Prerequisite conceptsGoroutines