essential-go
essential-go copied to clipboard
error at "closeing channels"
there is an error at Chapter 12. example:
ch := make(chan int) go func() { ch <- 1 close(ch) }() v, isClosed := <-ch fmt.Printf("received %d, is channel closed: %v\n", v, isClosed)
here, name "isClosed" doesn't mean "channel is closed", means "is ok to receive an value from channel"
so, the collect code is
ch := make(chan int) go func() { ch <- 1 close(ch) }() v, ok := <-ch if !ok { fmt.Printf("received %d, channel closed\n", v) }