Consider this playground
messages := make(chan int, 1)
done := make(chan bool)
go func() {
for {
select {
case msg := <- messages:
fmt.Println("receiver one", msg)
case signal := <-done :
fmt.Println(signal)
return
default:
fmt.Println("no message received")
}
}
}()
go func() {
for {
select {
case msg := <- messages:
fmt.Println("receiver two", msg)
case signal := <-done :
fmt.Println(signal)
return
default:
fmt.Println("no message received")
}
}
}()
go func() {
for i := 0; i < 2; i++ {
messages<-i
}
done<-true
done<-true
done<-true
}()
<-done
I am trying to simulate communicate from one thread to two other thread, but it seems like the above code is running fine in my local but not in playground.
Is there a trick to make the program work?