Sobes.tech
Junior — Middle

What happens if you perform a write to a channel whose buffer is completely full?

sobes.tech AI

Answer from AI

In Go, if you try to write a value to a buffered channel that is full, the write operation blocks until there is space available in the channel (i.e., until someone reads from the channel). This ensures synchronization between goroutines and prevents data loss.

Example:

ch := make(chan int, 2) // buffer of 2 elements
ch <- 1
ch <- 2
// ch <- 3 // this write will block until someone reads from ch
What happens if you perform a write to a channel… - sobes.tech