Created
May 2, 2017 19:17
-
-
Save gillesdemey/8a9dca11667c3a9f642a7fbdbde8d8b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"time" | |
) | |
func pinger(channel chan<- string) { | |
for { | |
channel <- "ping" | |
} | |
} | |
func ponger(channel chan<- string) { | |
for { | |
channel <- "pong" | |
} | |
} | |
func printer(channel <-chan string) { | |
for { | |
msg := <-channel | |
fmt.Println(msg) | |
time.Sleep(time.Second * 1) | |
} | |
} | |
func main() { | |
channel := make(chan string) | |
go pinger(channel) | |
go ponger(channel) | |
go printer(channel) | |
var input string | |
fmt.Scanln(&input) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment