Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error at "closeing channels" #9

Open
samuelyao314 opened this issue Dec 11, 2018 · 2 comments
Open

error at "closeing channels" #9

samuelyao314 opened this issue Dec 11, 2018 · 2 comments

Comments

@samuelyao314
Copy link

No description provided.

@samuelyao314
Copy link
Author

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"

@samuelyao314
Copy link
Author

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)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant