Problem Statement
Master all channel operations and their edge cases. This knowledge is essential for writing correct concurrent Go programs.
Channel Behavior Reference
| Operation | Nil Channel | Closed Channel | Open Channel |
|---|---|---|---|
ch <- v (send) | Blocks forever | PANIC | Blocks until received |
<-ch (receive) | Blocks forever | Returns zero, false | Blocks until sent |
close(ch) | PANIC | PANIC | Closes successfully |
Key Interview Questions
Q1: What happens if you send to a closed channel?
Q2: What happens if you receive from a closed channel?
Q3: What happens if you send/receive on a nil channel?
Use case: Disable a select case dynamically by setting channel to nil.