Code : https://play.golang.org/p/Oh3oTa7GIPX
type a struct {
c chan bool
}
func (a *a) do() {
a.c <- true
}
type b struct {
c chan bool
a a
}
func main() {
b := b{
c: make(chan bool),
a: a{c: make(chan bool)},
}
go b.s()
b.c <- true
// below is to stay main gorutine alive
done := make(chan bool)
go func() {
time.Sleep(10 * time.Second)
done <- true
}()
for {
select {
case <-done:
fmt.Println("Done!")
return
}
}
}
func (b *b) s() {
for {
select {
case <-b.c:
fmt.Println("b c")
b.a.do()
case <-b.a.c:
fmt.Println("b a c")
}
}
}
Actual Output of above is
b c
Done!
Expected Ouput:
b c
b a c
Done !
I am not getting why is it not printing b a c
?
Code is self explanatory, if it still requires more details please ask