Search⌘ K

Channels

Explore how channels work in Go to send and receive values between goroutines, enabling synchronization without explicit locks. Understand buffered and unbuffered channels, blocking behavior, and see examples of concurrency in action.

We'll cover the following...

About channels

Channels are pipes through which you can send and receive values using the channel operator, <-.

Go (1.6.2)
ch <- v // Send v to channel ch.
v := <-ch // Receive from ch, and
// assign value to v.

(The data flows in the direction of the arrow.)

Like maps and slices, channels must be created before use:

Go (1.6.2)
ch := make(chan int)

By default, sends and receives block wait until the other side is ready. This ...