go_playground/5-go-by-example/24-channels.go

17 lines
342 B
Go

// Channels are the pipes that connect concurrent goroutines
package main
import "fmt"
func main() {
// create new channel with make(chan val-type)
messages := make(chan string)
// send a value into a channel, here "ping"
go func() { messages <- "ping" }()
// receives a value from the channel
msg := <-messages
fmt.Println(msg)
}