Idempotent Channel Creation

25 views
Skip to first unread message

Wai Lee Chin Feman

unread,
Apr 2, 2013, 11:34:56 PM4/2/13
to alep...@googlegroups.com
Hi everyone,

I have a situation where I am creating channels and wiring them up dynamically:

--------------------------------------------------------------------------
(def dumping-ground (named-channel "dumping-ground"))

(defn build-and-wire [name]
  (let [created-channel (named-channel name)]
    (siphon (map* inc created-channel) dumping-ground)))
--------------------------------------------------------------------------

Now, this works great. (build-and-wire "thomas-mann")  will give me what I want.

The problem is that this is not idempotent.  If I call build-and-wire twice with the same name, I will wind up with more stuff in the dumping ground than I was hoping for.  In the following console session, I hope to only see "100" printed once:

-------------------------------------------------------------------------
moose.core=> (receive-all dumping-ground prn)
true
moose.core=> (build-and-wire "thomas-mann")
true
moose.core=> (build-and-wire "thomas-mann")
true
moose.core=> (receive-all dumping-ground prn)
true
moose.core=> (enqueue (named-channel "thomas-mann") 99)
100
100
-------------------------------------------------------------------------

Can you all think of a way to make this function idempotent?  Can I examine the channel named "thomas-mann", and check if it is already wired up?  If I can check whether or not it's connected to dumping-ground, then I'm able to know whether or not to call siphon.

Any ideas?

Thanks!

Zach Tellman

unread,
Apr 2, 2013, 11:48:35 PM4/2/13
to alep...@googlegroups.com

Siphon is idempotent, actually. The problem is the intermediate transformation creates new channels each time. Is there any reason not to do the wiring in the on-create callback of named-channel?

--
You received this message because you are subscribed to the Google Groups "Aleph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aleph-lib+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Wai Lee Chin Feman

unread,
Apr 3, 2013, 9:39:55 AM4/3/13
to alep...@googlegroups.com
A-ha.  I didn't see that there was a callback for the function.  That solves the problem, thanks!


--
You received this message because you are subscribed to a topic in the Google Groups "Aleph" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/aleph-lib/w8lsheWb6F4/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to aleph-lib+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages