My first channel program is four statements: ch := make(chan int); ch <- 42; v := <-ch; fmt.Println(v). It aborts with "fatal error: all goroutines are asleep - deadlock!" on the send. A second attempt, which starts three worker goroutines that send results and then ranges over the channel in main, prints the three results and then dies with the same error.
Why can I not send and then receive on the same channel in one goroutine, and what is the correct way to collect results from several goroutines and finish cleanly?




