The unidirectional buffer
Messages can be sent and received from a channel. However, when goroutines use channels for communication, they are generally going to be for a single purpose: either to send or receive from a channel. Go allows us to specify whether a channel being used by a goroutine is for sending or receiving messages. It accomplishes this with the help of unidirectional channels. Once a channel has been identified as being unidirectional, we cannot perform the other operation on them. This means that a unidirectional send channel cannot be used to receive messages, and a unidirectional receive channel cannot be used to send messages. Any attempts to do so would be caught by the Go compiler as compile-time errors.
Here is an ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access