go by example part 3

This commit is contained in:
2022-01-05 22:56:08 +01:00
parent c1b7c64da2
commit c5983176c5
10 changed files with 337 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
// 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)
}