Reading from a closed channel

This commit is contained in:
Mihalis Tsoukalos 2019-03-16 08:33:03 +02:00
commit c8508bb749

20
ch09/readClose.go Normal file
View 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)
}