What happens internally when you send a value to a closed channel? What about receiving from a closed channel?
Last updated
Sending on a closed channel panics (
send on closed channel), so only the sender should close. Closing a closed or nil channel also panics.Receiving drains remaining buffered values first, then returns the zero value immediately without blocking.
Detect closure with
v, ok := <-ch(okis false when closed and empty). Arangeloop exits cleanly on close.