Created
February 7, 2016 16:57
-
-
Save alexchowle/ef350894ec0c3d10aa53 to your computer and use it in GitHub Desktop.
Revisions
-
Alex Howle revised this gist
Feb 7, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -24,7 +24,7 @@ func pinger(pingChan chan<- string) { } func ponger(pingChan <-chan string, pongChan chan<- string) { // receive the ping fmt.Println("ponger received", <-pingChan) // respond with a pong -
Alex Howle created this gist
Feb 7, 2016 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ package main import ( "fmt" ) func main() { pingChan := make(chan string) pongChan := make(chan string) go printer(pongChan) go pinger(pingChan) go ponger(pingChan, pongChan) // Need to block until all complete var input string fmt.Scanln(&input) } func pinger(pingChan chan<- string) { // Send a ping fmt.Println("pinger sending \"ping\"") pingChan <- "ping" } func ponger(pingChan <-chan string, pongChan chan<- string) { // receive and discard the ping fmt.Println("ponger received", <-pingChan) // respond with a pong fmt.Println("ponger replying with \"pong\"") pongChan <- "pong" } func printer(pongChan <-chan string) { // read the pong fmt.Println("printer received", <-pongChan) }