Stage 1 · Code
Packages, Modules & Concurrency Intro
Channels
Communicate safely between goroutines using channels — Go's built-in typed message pipes.
Creating and Using Channels
A channel is a typed conduit for sending values between goroutines. Send with ch <- value and receive with value := <-ch. By default, both operations block until the other side is ready.
This is Go's concurrency mantra. Instead of having goroutines write to shared variables (which requires mutexes), pass data through channels. The ownership of a value transfers when it is sent — the sender no longer touches it.
Buffered Channels
A buffered channel has a capacity. Sends block only when the buffer is full; receives block only when the buffer is empty. Use buffering to decouple producers and consumers.
Closing and Ranging
close(ch) signals that no more values will be sent. Receivers can detect closure via the comma-ok form or by ranging — range ch loops until the channel is closed and drained.
select
select waits on multiple channel operations simultaneously, picking whichever is ready first. If multiple are ready, it chooses one at random.
Channel Directions
Function parameters can declare a channel as send-only (chan<-) or receive-only (<-chan). This documents intent and prevents accidental misuse at compile time.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.