Skip to main content
InterviewHubPRO
Section Overview
Q19

Question 19 of 50

Part 2: Concurrency, Channels & The GMP Scheduler (16 - 32)

38%
Golang & Concurrency (50 Qs)•Part 2: Concurrency, Channels & The GMP Scheduler (16 - 32)

Rules of Channel Closing: Why should only the sender close, and what happens when reading from a closed channel?

senior LevelGolang

In Simple Words:

  1. Closing an already closed channel triggers a fatal runtime panic.
  2. Sending to a closed channel triggers a fatal runtime panic.
  3. Reading from a closed channel NEVER blocks: it returns the zero-value of the type and false (val, ok := <-ch).
  4. Golden Rule: Always close a channel from the Sender side, never the receiver side, and never when multiple concurrent senders exist.