Hi François,

That makes sense. I think I had read that discussion a while ago but hadn't 
really grokked it.

Thanks!

Juan

On Tuesday, March 11, 2014 10:42:04 AM UTC-3, François Rey wrote:
>
>  On 10/03/14 15:37, juan.facorro wrote:
>  
> I have taken this approach as well, but I can can't seem to find a good 
> answer to this question: When you create a bunch of elements with their 
> corresponding channels to handle certain events, how do you handle the 
> closing of those channels and the termination of the related *go* blocks 
> once you remove the elements?
>  
>
> I'm not a specialist of core.async (so anyone please correct me if I'm 
> wrong) but here's what I understand.
>
> Go blocks aggregate into FSMs which can be garbage 
> collected<http://stackoverflow.com/questions/18800440/javascript-and-garbage-collection>like
>  any other objects. When parked go blocks are queued into the channel. 
> So what it comes down to is being mindful of where you keep references to 
> channels. More precisely, don't hold a reference to the channel beyond the 
> scope of its producers and its reading go blocks. That probably means 
> locality of readers (go blocks) is often preferable to a longer-lived go 
> block. I guess it's the same mindfulness that goes on when keeping 
> references to call-back handlers.
>
> See also this discussion:
> https://groups.google.com/forum/#!topic/clojure/_KzEoq0XcHQ
>
> From Timothy you'll read that go block are garbage collected:
>
> When go's are parked, they are put into a queue on the channel, thus when 
> the channel is unreachable (besides inside the go block) both are 
> collected, and the thread of execution is effectively terminated.
>
>
> From Brandon Bloom you'll read that:
>
> Querying the state of a channel at worst leads to race conditions and at 
> best leads to bad design.
> You're only supposed to close a channel from the producer side. So if 
> you're the only writer, then you know if you've closed the channel or not. 
> If there are multiple writers, then need to be coordinated in some way. 
> Typically, they would alt! against reading from a control channel and 
> writing to the output channel. When you get a shutdown signal from the 
> control channel, you stop writing.
> (...)
> It is a programming error to write a message to a closed channel. "close" 
> is not a resource cleanup operation, it is a control signal. It "flows" in 
> the same direction as the messages sent on the channel itself. If the 
> receiver were allowed to close the channel, then the sender would have no 
> way of avoiding a closed/write race condition.
>
>
>
> 

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to