Skip to content

Instantly share code, notes, and snippets.

@rooklift
Created February 20, 2016 19:01
Show Gist options
  • Save rooklift/5ae131838138b10ac1f0 to your computer and use it in GitHub Desktop.
Save rooklift/5ae131838138b10ac1f0 to your computer and use it in GitHub Desktop.
Windows didn't like this at all
package main
import "fmt"
import "time"
var finalchan = make(chan time.Time)
func chain(n int, in chan time.Time) {
var out chan time.Time
if n > 0 {
out = make(chan time.Time)
go chain(n - 1, out)
}
for {
t := <- in
if out != nil {
out <- t
} else {
finalchan <- t
}
}
}
func main() {
out := make(chan time.Time)
go chain(1000000, out)
out <- time.Now()
t := <- finalchan
fmt.Println(time.Now().Sub(t))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment