package main
func main() {
c := make(chan int, 1)
for done := false; !done; {
select {
default:
print(1)
done = true
case <-c:
print(2)
c = nil
case c <- 1:
print(3)
}
}
}
Choices:
Answer: 321
Run it on Go play.
Key points:
c <- 1
is non-blocking.
So the last case
branch is chosen.
<-c
is non-blocking.
So the first case
branch is chosen.
default
branch is chosen.