Reading from a closed channel
This commit is contained in:
parent
393fdd4139
commit
c8508bb749
1 changed files with 20 additions and 0 deletions
20
ch09/readClose.go
Normal file
20
ch09/readClose.go
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
willClose := make(chan int, 10)
|
||||
// Write some data to the channel
|
||||
willClose <- -1
|
||||
willClose <- 0
|
||||
willClose <- 2
|
||||
// Empty channel
|
||||
<-willClose
|
||||
<-willClose
|
||||
<-willClose
|
||||
close(willClose)
|
||||
read := <-willClose
|
||||
fmt.Println(read)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue