Skip to main content
Module 7 · Lesson 2 of 532/50 in the course~15 min
Module lessons (2/5)

Channel: typed communication

Lesson preview5 hands-on exercises readyCourse Go · Module 7 — Competition

ch := make(chan int), ch <- v, v := <-ch, channel buffered vs unbuffered, closing.

What you'll learn in this lesson

  • Create unbuffered (make(chan T)) and buffered (make(chan T, N)) channels by understanding their blocking rules.
  • Apply security rules for close(ch) and consume streams with for v := range ch.
  • Specify directionality (chan<- T, <-chan T) in function signatures and use signal channels chan struct{}.

Overview

"Do not communicate by sharing memory; instead, share memory by communicating." channels are thread-safe queues through which goroutines exchange values and synchronize their execution.

When no more data arrives, the sender invokes close(ch) alone. The recipient can read until completely empty with for v := range ch or check v, ok := <-ch:

Sections covered in this lesson

  1. 1Unbuffered vs Buffered and rendezvous
  2. 2Closing close(ch) and reading with for range
  3. 3Directionality in signatures and chan struct{}
  4. 4One-shot signal with chan struct{}
  5. 5Guided practice
  6. 6Check for understanding
Pro Lesson · Module 7 — Competition

Unlock "Channel: typed communication" and the full Course Go curriculum

`ch := make(chan int)`, `ch <- v`, `v := <-ch`, channel buffered vs unbuffered, closing.

Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in Course Go plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.