Sobes.tech
Junior — Middle

How is data transmitted through a non-buffered communication channel?

sobes.tech AI

Answer from AI

Data transfer through an unbuffered channel in Go occurs synchronously: the sender blocks until the receiver reads the data, and vice versa. This provides direct synchronization between goroutines.

Example:

ch := make(chan int) // unbuffered channel

// Sender
go func() {
    ch <- 42 // blocks until the receiver reads
}()

// Receiver
val := <-ch // blocks until a value appears
fmt.Println(val) // will output 42

Thus, data is transferred directly, without intermediate storage, ensuring synchronization between sender and receiver.

How is data transmitted through a non-buffered… - sobes.tech