4

I'm using Lamina to implement a basic pubsub pattern.

When a client subscribes to a topic I create a new channel for it (if it doesn't already exist) and then siphon it to the client's channel. However, I can't figure out how to reverse this to let the client unsubscribe. I've been searching the docs and googling but can't find anything.

How do I undo what siphon does?

Ilia Choly
  • 18,070
  • 14
  • 92
  • 160

2 Answers2

3

You can fork the upstream channel above the siphon and then ground the downstream channel, or if your graph permits can you just close the channel you no longer want siphoning form the upstream channel.

ps: i'll try to add an example later ...

Arthur Ulfeldt
  • 90,827
  • 27
  • 201
  • 284
1

Typically you'd make a bridge channel that you can close, so the linkage is:

topic-channel -> bridge-channel -> client-channel

In 0.5.0, this is easy because siphon is variadic:

(defn cancellable-siphon [src dst]
   (let [bridge (channel)]
     (siphon src bridge dst)
     #(close bridge)))
ztellman
  • 756
  • 4
  • 7
  • would it be a better idea to just have a `receive-all` which does something like `#(doseq [ch subscribers] (enqueue ch %))`, or is the overhead introduced with the bridge `channel` negligible? – Ilia Choly Oct 04 '12 at 13:50
  • 1
    Message propagation using the existing primitives is almost always going to be faster than something you write yourself (each additional node is ~70ns to traverse). Also using `enqueue` is rarely a good idea, because it breaks the auto-closing behavior by creating message flows that are implicit rather than explicit. – ztellman Oct 04 '12 at 16:31