Junior — Middle
Kuidas toimub andmete edastamine mittebuferiseeritud sidekanali kaudu?
sobes.tech AI
Vastus AI-lt
Data transfer via a non-buffered channel in Go occurs synchronously: the sender blocks until the receiver reads the data, and vice versa. This ensures direct synchronization between goroutines.
Example:
ch := make(chan int) // non-buffered channel
// Sender
go func() {
ch <- 42 // blocks until the receiver reads
}()
// Receiver
val := <-ch // blocks until a value appears
fmt.Println(val) // will print 42
Thus, data is transmitted directly, without intermediate storage, guaranteeing synchronization between sender and receiver.