Add ping pong

This commit is contained in:
Sangeeth Sudheer 2024-04-28 15:27:07 +05:30
parent 132e8a621f
commit 7d762500e6
Signed by: x
GPG Key ID: F6D06ECE734C57D1

View File

@ -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()
} }