Add ping pong
This commit is contained in:
parent
132e8a621f
commit
7d762500e6
@ -40,7 +40,25 @@ func bufferedChannels() {
|
|||||||
fmt.Println("Done")
|
fmt.Println("Done")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ping(pingc chan<- string, msg string) {
|
||||||
|
pingc <- msg
|
||||||
|
}
|
||||||
|
|
||||||
|
func pong(pingc <-chan string, pongc chan<- string) {
|
||||||
|
fmt.Println("pong() received message:", <-pingc)
|
||||||
|
pongc <- "pong!"
|
||||||
|
}
|
||||||
|
|
||||||
|
func pingPong() {
|
||||||
|
header("Channel Directions")
|
||||||
|
pingc, pongc := make(chan string, 1), make(chan string, 1)
|
||||||
|
ping(pingc, "ping!")
|
||||||
|
pong(pingc, pongc)
|
||||||
|
fmt.Println("Received message in pingPong():", <-pongc)
|
||||||
|
}
|
||||||
|
|
||||||
func Channels() {
|
func Channels() {
|
||||||
simpleChannels()
|
simpleChannels()
|
||||||
bufferedChannels()
|
bufferedChannels()
|
||||||
|
pingPong()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user