c1 0
fun2 returning
c2 0
c3 0
c4 0
fun4 returning
fun3 returning
done
Wow, kind of embarrassing. I appreciate your patience.I'm about 90% sure this link leads to an example of a writer blocked on
a channel that will no longer be read from.
http://play.golang.org/p/m_2FAIiW1o
On Mon, Jul 2, 2012 at 3:14 PM, David Symonds <ds...@golang.org> wrote:
> If a producer doesn't explicitly give you a way to stop itself, thenI understand this, but I think this behavior is going to surprise
> you have to read from the channel until it closes it because it needs you too.
people. If I have a goroutine generating the Fibonacci sequence to
infinity, it's not clear why there needs to be some explicit stop
indication in a garbage-collected language.
--
=====================
http://jessta.id.au
You have to admit - close(quit) is a rather cryptic way of saying "I'm
no longer interested in channel c."
So how does one handle timeouts perfectly cleanly? It's a bit important for services to be careful of resource consumption.
On Mon, Jul 2, 2012 at 11:13 PM, Jesse McNelis <jes...@jessta.id.au> wrote:I see what you mean, but in the current implementation the sender just
> On Tue, Jul 3, 2012 at 1:08 PM, Maxim Khitrov <m...@mxcrypt.com> wrote:
>> IMHO, a better solution would be to define the semantics of calling
>> close() on a receive-only channel, and adding "comma ok" send form to
>> let the senders determine whether any receive ends of a channel are
>> still open.
>
> What does the sender do with the value it just generated?
> What if the generation had side effects?
> You'd need to know the internal implementation to know if it's safe
> for a receiver to close a channel.
> This has been discussed and it's a bad idea.
becomes permanently blocked. You have a memory leak, which is going to
surprise many newcomers to Go (as evidenced by the number of questions
related to garbage collection of goroutines). I'm not saying that my
method is ideal, but in many simple cases it would result in cleaner
and clearer code.
You have to admit - close(quit) is a rather cryptic way of saying "I'm
no longer interested in channel c."
To keep the talk simple, I deliberately avoided all these issues. They are in fact a suitable topic for a second talk.
Two different channels. Paul and Rob suggest creating a separate
channel called 'quit' that is closed by the receiver as a way of
asking the sender(s) to terminate. I don't really like this method (or
rather I really don't like it), because it increases the complexity of
the code for no apparent benefit
If I have a goroutine generating the Fibonacci sequence to
infinity, it's not clear why there needs to be some explicit stop
indication in a garbage-collected language.
Two different channels. Paul and Rob suggest creating a separate
channel called 'quit' that is closed by the receiver as a way of
asking the sender(s) to terminate. I don't really like this method (or
rather I really don't like it), because it increases the complexity of
the code for no apparent benefit
If I have a goroutine generating the Fibonacci sequence to
infinity, it's not clear why there needs to be some explicit stop
indication in a garbage-collected language.
On Mon, Jul 2, 2012 at 8:53 PM, Maxim Khitrov <m...@mxcrypt.com> wrote:On Mon, Jul 2, 2012 at 11:13 PM, Jesse McNelis <jes...@jessta.id.au> wrote:I see what you mean, but in the current implementation the sender just
> On Tue, Jul 3, 2012 at 1:08 PM, Maxim Khitrov <m...@mxcrypt.com> wrote:
>> IMHO, a better solution would be to define the semantics of calling
>> close() on a receive-only channel, and adding "comma ok" send form to
>> let the senders determine whether any receive ends of a channel are
>> still open.
>
> What does the sender do with the value it just generated?
> What if the generation had side effects?
> You'd need to know the internal implementation to know if it's safe
> for a receiver to close a channel.
> This has been discussed and it's a bad idea.
becomes permanently blocked. You have a memory leak, which is going to
surprise many newcomers to Go (as evidenced by the number of questions
related to garbage collection of goroutines). I'm not saying that my
method is ideal, but in many simple cases it would result in cleaner
and clearer code.
You have to admit - close(quit) is a rather cryptic way of saying "I'm
no longer interested in channel c."What it comes down to is this: closing a channel is a communication operation. Channels are one-way pipes. Either you complicate the implementation (and constrain future implementations and optimizations) by allowing this one particular case of two-way communication for an uncommon case (bad) or you let programmers account for it when necessary with a secondary channel (good).
--dho