concurrency-in-go-src | Full sourcecode for the book , Concurrency in Go | Websocket library
kandi X-RAY | concurrency-in-go-src Summary
kandi X-RAY | concurrency-in-go-src Summary
Full sourcecode for the book, "Concurrency in Go" published by O'Reilly.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of concurrency-in-go-src
concurrency-in-go-src Key Features
concurrency-in-go-src Examples and Code Snippets
Community Discussions
Trending Discussions on concurrency-in-go-src
QUESTION
I read the book "Concurrency in Go" written by Katherine Cox-Buday and I don't understand comments for examples of buffered channels.
The author says:
...ANSWER
Answered 2021-Jun-12 at 18:10Yes, it sounds like this book needs a better editor!
the channel capacity is indeed indicated as the 2nd argument to make
:
QUESTION
I was trying to understand the following piece of code that reads from a channel of channels. I am having some difficulties wrapping my head around the idea.
...ANSWER
Answered 2019-Aug-04 at 05:59In both cases, the select is done to avoid blocking — if the reader isn't reading from our output channel, the write might block (maybe even forever), but we want the goroutine to terminate when the done
channel is closed, without waiting for anything else. By using the select
, it will wait until either thing happens, and then continue, instead of waiting indefinitely for the write to complete before checking done
.
As for the other question, "why are we not returning here?": well, we could. But we don't have to, because a closed channel remains readable forever (producing an unlimited number of zero values) once it's been closed. So it's okay to do nothing in those "bottom" selects
; if done
was in fact closed we will go back up to the top of the loop and hit the case <-done: return
there. I suppose it's a matter of style. I probably would have written the return
myself, but the author of this sample may have wanted to avoid handling the same condition in two places. As long as it's just return
it doesn't really matter, but if you wanted to do some additional action on done
, that behavior would have to be updated in two places if the bottom select returns, but only in one place if it doesn't.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install concurrency-in-go-src
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page