Senior
What entity is used to transfer data between goroutines?
sobes.tech AI
Answer from AI
In Go, the entity used for passing data between goroutines is called a channel. 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 a value into the channel
}()
value := <-ch // receive a value from the channel
fmt.Println(value) // will output 42
Channels can be buffered and unsafe, which allows flexible management of synchronization and data exchange between goroutines.