From c8508bb749040de5344ba82dbf3662e4cd45ae7b Mon Sep 17 00:00:00 2001 From: Mihalis Tsoukalos Date: Sat, 16 Mar 2019 08:33:03 +0200 Subject: [PATCH] Reading from a closed channel --- ch09/readClose.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 ch09/readClose.go diff --git a/ch09/readClose.go b/ch09/readClose.go new file mode 100644 index 0000000..2159600 --- /dev/null +++ b/ch09/readClose.go @@ -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) +}