package main
import (
"fmt"
)
func ready(c chan int, quit chan bool){
for {
j := <- c
fmt.Println("ready ", j)
}
<- quit
}
func main() {
c := make(chan int)
quit := make(chan bool)
go ready(c, quit)
for i := 0; i < 2; i++ {
c <- i
fmt.Println("main ", i)
}
quit <- false
}
错误是这样的:
fatal error: all goroutines are asleep - deadlock!
```
j, ok := <- c
if !ok {
break
}
```
```
close(c)
quit <- false
```
#2