Skip to content

Instantly share code, notes, and snippets.

@gillesdemey
Created May 2, 2017 19:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gillesdemey/8a9dca11667c3a9f642a7fbdbde8d8b2 to your computer and use it in GitHub Desktop.
Save gillesdemey/8a9dca11667c3a9f642a7fbdbde8d8b2 to your computer and use it in GitHub Desktop.
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