Skip to content

Instantly share code, notes, and snippets.

@jordanorelli
Created July 18, 2012 19:38
Show Gist options
  • Save jordanorelli/3138363 to your computer and use it in GitHub Desktop.
Save jordanorelli/3138363 to your computer and use it in GitHub Desktop.
a channel of functions
package main
import (
"fmt"
"math/rand"
"time"
)
func main() {
rand.Seed(time.Now().Unix())
rand.Int31n(4)
c := make(chan func() int)
go func() {
for {
var fn func() int
switch rand.Int31n(4) {
case 0:
fn = func() int {
return 0
}
case 1:
fn = func() int {
return 1
}
case 2:
fn = func() int {
return 2
}
case 3:
fn = func() int {
return 3
}
}
c <- fn
}
}()
for fn := range c {
fmt.Println(fn())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment