What are channel direction types (send-only and receive-only), and why are they useful in function signatures?
Last updated
chan<- Tis send-only and<-chan Tis receive-only (the arrow shows data flowing into or out of the channel).In function signatures they document whether a function produces or consumes. The compiler also rejects misuse, such as sending on or closing a receive-only channel.
A bidirectional
chan Tconverts implicitly to either directional type when passed, but not the reverse.