Senior
Milline üksus kasutatakse andmete edastamiseks goroutine'ide vahel
sobes.tech AI
Vastus AI-lt
In Go, for transmitting data between goroutines, an entity called channel is used. Channels allow safe data exchange, synchronizing the execution of goroutines.
Example of using a channel:
ch := make(chan int) // create a channel for transmitting int
go func() {
ch <- 42 // send value to the channel
}()
value := <-ch // receive value from the channel
fmt.Println(value) // will print 42
Channels can be buffered and unsafe, which allows flexible management of synchronization and data exchange between goroutines.