30 lines
433 B
Go
30 lines
433 B
Go
package main
|
|
|
|
import "fmt"
|
|
import "time"
|
|
|
|
func pinger(c chan string) {
|
|
c <- "ping"
|
|
}
|
|
func ponger(c1 chan string, c2 chan string) {
|
|
<-c1
|
|
c2 <- "pong"
|
|
}
|
|
func printer(c chan string) {
|
|
msg := <-c
|
|
fmt.Println(msg)
|
|
time.Sleep(time.Second)
|
|
}
|
|
|
|
func main() {
|
|
pingChan, pongChan := make(chan string), make(chan string)
|
|
|
|
go pinger(pingChan)
|
|
go ponger(pingChan, pongChan)
|
|
go printer(pongChan)
|
|
|
|
var input string
|
|
fmt.Scanln(&input)
|
|
|
|
}
|