As Peter Russell already mentioned, the channel you are using is
unbuffered, so since no-one is listening at the moment when you write
to the channel, the call will block.
Usually channels are used to communicate between different threads of
operation (go-routines), you could use it like this:
func main(){
ch := make(chan int)
go func() { ch <- 2 }()
i :=<- ch
fmt.Printf("%d",i)
}
This will create an anonymous function that will write to the channel,
and execute it in a separate thread. Because this runs in parallel,
the following line, where you read from the channel, is reached, which
will un-block the writer, and all is well.
You can play with it here:
http://play.golang.org/p/macbX7u2up
--
远洋 / Daniël Bos