i am trying to understand go routines and how it works. in the below example i have two go routines each sending some messege via channels.i was expecting the channel ch will send messege first but why is go readword(ch) execute after go timeout(t). if i change the order of the go routines call inside main function then readword(ch) will execute first.i am getting very confused about go routines? any help?
func readword(ch chan string) {
fmt.Println("Type a word, then hit Enter.")
var word string
fmt.Scanf("%s", &word)
ch <- word
}
func timeout(t chan bool) {
t <- false
}
func main() {
ch := make(chan string)
go readword(ch)
t := make(chan bool)
go timeout(t)
select {
case word := <-ch:
fmt.Println("Received", word)
case <-t:
fmt.Println("Timeout.")
}
}