Explain the concept of channel direction and why it's useful.

  • Channels have only one direction - sending data.
  • Channels have two directions - sending and receiving data.
  • Channels have three directions - sending, receiving, and both.
  • Channels have no direction - they are bidirectional.
Channels in Go have two directions: sending and receiving. This is useful because it enforces a clear separation of concerns in concurrent code. It allows one goroutine to send data to a channel, and another goroutine to receive and process that data, ensuring safe communication between them. This prevents data races and simplifies synchronization in multi-threaded programs.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *