On the closed channels point - reading from a channel returns a second boolean argument that indicates if the channel is closed or not. So, for your example you could do n, ok := <-ca and if ca had been closed the value of ok would be false
n, ok := <-ca
ca
ok
false
Thanks!
Sameer Ajmani pointed it out on Twitter. I updated the post.
That's one problem down!
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
On the closed channels point - reading from a channel returns a second boolean argument that indicates if the channel is closed or not. So, for your example you could do
n, ok := <-ca
and ifca
had been closed the value ofok
would befalse
Thanks!
Sameer Ajmani pointed it out on Twitter. I updated the post.
That's one problem down!