go by example part 3
This commit is contained in:
16
5-go-by-example/24-channels.go
Normal file
16
5-go-by-example/24-channels.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user