Created
November 20, 2015 15:17
-
-
Save thedeemon/79cdd725496711af446c 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 player(from chan int, to chan int, end chan int) { | |
for { | |
v := <-from | |
to <- v + 1 | |
if v >= 100000 { | |
end <- v | |
return | |
} | |
} | |
} | |
func main() { | |
t0 := time.Now() | |
c1 := make(chan int) | |
c2 := make(chan int) | |
c3 := make(chan int) | |
go player(c1, c2, c3) | |
go player(c2, c1, c3) | |
c1 <- 1 | |
res := <-c3 | |
t1 := time.Now() | |
fmt.Println("got ", res, " ", t1.Sub(t0)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment