Skip to content

Instantly share code, notes, and snippets.

@thedeemon
Created November 20, 2015 15: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 thedeemon/79cdd725496711af446c to your computer and use it in GitHub Desktop.
Save thedeemon/79cdd725496711af446c to your computer and use it in GitHub Desktop.
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