Created
June 12, 2011 19:11
-
-
Save iporsut/1021887 to your computer and use it in GitHub Desktop.
PingPong (Msg passing with Go)
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 characters
package main | |
import ( | |
"fmt" | |
) | |
var pongChan = make(chan string,1) | |
var pingChan = make(chan string,1) | |
var state = make(chan int) | |
func ping(){ | |
for i:= 1; i<= 100;{ | |
var b string | |
pongChan <- "Ping" | |
b = <-pingChan | |
fmt.Println(b) | |
i++ | |
} | |
state <-1 | |
} | |
func pong(){ | |
for i:= 1; i<= 100;{ | |
var b string | |
b = <-pongChan | |
fmt.Println(b) | |
pingChan <- "Pong" | |
i++ | |
} | |
} | |
func main() { | |
go ping() | |
go pong() | |
<-state | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment