This question already has an answer here:
The blow code does not print anything even if main function is writing to channel. Is it because the goroutine running the anonymous function exited before channel could receive any value?
package main
import "fmt"
func main() {
ch := make(chan int)
go func () {for{fmt.Println(<-ch)}} ()
ch <- 1
}
</div>