Yea that's very helpful. When you say "the channel can never give them a
value," is that because the channel is no longer in scope?
So
(def c (chan))
(dotimes [x 10]
(go ( Channels are not tied to anything, so once your code stops referencing them,
> they are garbage collected.
>
> Go bloc
Channels are not tied to anything, so once your code stops referencing
them, they are garbage collected.
Go blocks are actually nothing more than pretty callbacks that are attached
to channels. So if a go is waiting for a put or a take from a channel, it
will be GC'd with the channel. I could go i
Great!
I've used alts! before with control channels which is definitely useful as
well.
Timothy, can you elaborate a little? I'm still a little unclear when
channels are garbage collected. It it an issue to leave channels open after
you've stopped using them? I always feel a little strange co
Also, go blocks that are waiting on channels that are garbage collected
will be garbage collected themselves. This means I often just re-compile an
entire namespace, this redefines the channel, re-binds the def the channel
is attached to, and recreates all gos. The channel is now free go be GC'd
al
I always pass a control-channel into go loops, by which I can close it:
(defn looper [event-ch ctl-ch]
(go-loop []
(alt! event-ch ([event _] (handle-event event) (recur))
ctl-ch ([msg _] (assert (nil? msg))
This also makes it easy to funnel more control events then just end-
When working with channels and go blocks with nRepl, I often want to do
something like this.
(def events (event-generator))
(go-loop []
(when-let [event (http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure"