3 ms·
You can't send closures over channels in Go.
by gecko 14y ago
You can't send closures over channels in Go.
- crawshaw 14y agoYou can: func main() { x := 4 f := func() { fmt.Println(x) } ch := make(chan func(), 1) ch <- f f2 := <-ch f2() x = 5 f2() } http://play.golang.org/p/NK5YLVT4zB http://play.golang.org/p/NK5YLVT4zB
- ithkuil 14y agotest := make(chan func (int) int) go func() { f := <- test fmt.Printf("%d\n", f(10)) }() test <- func(v int) int { return v * v }