25% off

Use code FUNCMAIN at checkout for 25% off all premium courses.

Get started →

Interactive Go · Lesson

Channels

Goroutines need a safe way to talk to each other. A channel is a typed pipe: one goroutine sends a value with ch <- v, another receives it with <-ch.

ch := make(chan int)
go func() { ch <- 42 }()  // send
n := <-ch                 // receive (blocks until a value arrives)

Sends and receives block until the other side is ready, which neatly synchronises the two goroutines — no locks required.

Your Quest

Launch a goroutine that sends "Victory!" into the messages channel. The <-messages receive already in place will print it.

Expected output:

Victory!

Hint

go func() { messages <- "Victory!" }().

Additional Scrolls of Wisdom