Sobes.tech
Senior

Mis on `<-ch` konstruktsioon Go-s?

sobes.tech AI

Vastus AI-lt

In Go, the <-ch construct is used to receive a value from the channel ch. It is a read operation from the channel that blocks until a value appears in the channel.

Example:

ch := make(chan int)
func() {
    ch <- 42 // send a value into the channel
}()

value := <-ch // read the value from the channel, blocks until the value is available
fmt.Println(value) // will print 42

Thus, <-ch is a syntax for receiving data from the channel, ensuring synchronization between goroutines.