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.
Loading...
Related Quiz
- Describe how you would write data to a file, ensuring that the file is properly closed afterward.
- The _____ statement is used to iterate over a range of values.
- What is the zero value in Go, and how does it apply to different data types?
- How would you design a Go program to handle multiple types of input, leveraging interfaces?
- What is the purpose of the append function in Go?