Search code examples
clojurepublish-subscribelamina-clojure

Lamina undo siphon - Clojure


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?


Solution

  • 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)))