Recall & Review
beginner
What happens when you close a channel in Go?
Closing a channel means no more values can be sent on it. Receivers can still receive remaining values until the channel is empty, then they get the zero value.
Click to reveal answer
beginner
Can you send values on a closed channel?
No. Sending on a closed channel causes a runtime panic (error).
Click to reveal answer
intermediate
What does a receive operation return when the channel is closed and empty?
It returns the zero value of the channel's type and false for the second value if using the two-value receive form.
Click to reveal answer
intermediate
How can you check if a channel is closed when receiving?
Use the two-value receive: v, ok := <-ch. If ok is false, the channel is closed and empty.
Click to reveal answer
intermediate
Is it safe to close a channel from multiple goroutines?
No. Closing a channel multiple times causes a panic. Only one goroutine should close the channel.
Click to reveal answer
What happens if you try to send a value on a closed channel?
✗ Incorrect
Sending on a closed channel causes a runtime panic in Go.
When receiving from a closed channel, what value do you get?
✗ Incorrect
After a channel is closed and emptied, receives return the zero value of the channel's type.
How do you detect if a channel is closed when receiving?
✗ Incorrect
The two-value receive form returns ok=false when the channel is closed and empty.
Who should close a channel?
✗ Incorrect
The sender should close the channel to signal no more values will be sent.
What happens if multiple goroutines close the same channel?
✗ Incorrect
Closing a channel more than once causes a panic.
Explain what happens when a Go channel is closed and how receivers behave afterwards.
Think about what sending and receiving do after closing.
You got /4 concepts.
Describe best practices for closing channels in concurrent Go programs.
Who should close and why?
You got /4 concepts.