This question already has an answer here:
- Why is this Go code blocking? 3 answers
The following code run forever instead of stopping one second after the beginning. The go routine with the infinite loop seems to prevent the other one from sending to the timeout channel. Is that normal ?
func main(){
timeout:=make(chan int)
go func(){
time.SLeep(time.Second)
timeout<-1
}()
res:=make(chan int)
go func(){
for{
}
res<-1
}()
select{
case<-timeout:
fmt.Println("timeout")
case<-res:
fmt.Println("res")
}
}
</div>