This question already has an answer here:
- No output from goroutine in Go 3 answers
I'm learning Go and I wanted to try goroutines and channels.
Here's my code:
package main
import "fmt"
func main(){
messages := make(chan string,3)
messages <- "one"
messages <- "two"
messages <- "three"
go func(m *chan string) {
fmt.Println("Entering the goroutine...")
for {
fmt.Println(<- *m)
}
}(&messages)
fmt.Println("Done!")
}
And here's the result:
Done!
I don't understand why my goroutine is never executed. The "Entering the goroutine" is not printed and I don't have any error message.
</div>