go-examples/pinger/main.go

30 lines
433 B
Go
Raw Normal View History

2017-07-08 12:54:39 +00:00
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)
}