more
This commit is contained in:
parent
6a9c1731b3
commit
098a71ef89
35
40-directions.go
Normal file
35
40-directions.go
Normal file
@ -0,0 +1,35 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func pinger(pings chan<- string) {
|
||||
for i := 0; i <= 10; i++ {
|
||||
pings <- "ping"
|
||||
}
|
||||
}
|
||||
|
||||
func ponger(pings <-chan string, pongs chan<- string) {
|
||||
for {
|
||||
<- pings
|
||||
pongs <- "pong"
|
||||
}
|
||||
}
|
||||
|
||||
func printer(pongs <-chan string) {
|
||||
for {
|
||||
msg := <- pongs
|
||||
fmt.Println(msg)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
var pings chan string = make(chan string)
|
||||
var pongs chan string = make(chan string)
|
||||
|
||||
go pinger(pings)
|
||||
go ponger(pings, pongs)
|
||||
go printer(pongs)
|
||||
|
||||
var input string
|
||||
fmt.Scanln(&input)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user