Recall & Review
beginner
What is an unbuffered channel in Go?
An unbuffered channel in Go is a channel with no capacity to hold data. It requires both sender and receiver to be ready at the same time for communication to happen, ensuring synchronization.
Click to reveal answer
beginner
What is a buffered channel in Go?
A buffered channel in Go has a capacity to hold a fixed number of values. Senders can send data without waiting for a receiver until the buffer is full, allowing asynchronous communication up to the buffer size.
Click to reveal answer
beginner
How do you create a buffered channel in Go?
You create a buffered channel using the make function with a capacity argument, like: ch := make(chan int, 3). This channel can hold 3 integers before blocking the sender.
Click to reveal answer
intermediate
What happens when you send to a full buffered channel?
When you send to a buffered channel that is full, the sending goroutine blocks until some data is received from the channel, freeing space in the buffer.
Click to reveal answer
intermediate
Why use buffered channels instead of unbuffered channels?
Buffered channels allow some decoupling between sender and receiver, letting the sender continue without waiting immediately. This can improve performance and avoid deadlocks in some cases.
Click to reveal answer
What does an unbuffered channel guarantee in Go?
✗ Incorrect
Unbuffered channels require sender and receiver to be ready at the same time, ensuring synchronization.
How do you declare a buffered channel with capacity 5 in Go?
✗ Incorrect
Use make with a second argument for capacity: make(chan int, 5).
What happens if you send to a buffered channel that is not full?
✗ Incorrect
If the buffer is not full, send does not block and proceeds immediately.
Which of these is true about buffered channels?
✗ Incorrect
Buffered channels hold multiple values up to their capacity before blocking the sender.
Why might you choose an unbuffered channel?
✗ Incorrect
Unbuffered channels ensure synchronization between sender and receiver on each message.
Explain the difference between buffered and unbuffered channels in Go.
Think about whether the sender waits or not.
You got /4 concepts.
Describe a situation where using a buffered channel is better than an unbuffered channel.
Consider when you want to let sender continue without waiting.
You got /3 concepts.