From 098a71ef898ecae4595420f12a1f3b51c75c07f9 Mon Sep 17 00:00:00 2001 From: Mark McGranaghan Date: Sun, 16 Sep 2012 16:19:36 -0700 Subject: [PATCH] more --- 40-directions.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 40-directions.go diff --git a/40-directions.go b/40-directions.go new file mode 100644 index 0000000..14a399c --- /dev/null +++ b/40-directions.go @@ -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) +}