github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/talks/2014/go4java/goroutines.go (about) 1 // +build OMIT 2 3 package main 4 5 import ( 6 "fmt" 7 "time" 8 ) 9 10 func f(left, right chan int) { 11 left <- 1 + <-right 12 } 13 14 func main() { 15 start := time.Now() 16 const n = 1000 17 leftmost := make(chan int) 18 19 right := leftmost 20 left := leftmost 21 for i := 0; i < n; i++ { 22 right = make(chan int) 23 go f(left, right) 24 left = right 25 } 26 27 go func(c chan int) { c <- 0 }(right) 28 29 fmt.Println(<-leftmost, time.Since(start)) 30 }