Skip to content

Instantly share code, notes, and snippets.

@raspasov
Last active August 29, 2015 14:11
Show Gist options
  • Save raspasov/81c678961b6292eebe04 to your computer and use it in GitHub Desktop.
Save raspasov/81c678961b6292eebe04 to your computer and use it in GitHub Desktop.
clojure core.async pub/sub
;create our publisher
(def pub-ch (chan))
(def publication (pub pub-ch #(:topic %)))
;sub chans
(def sub-1 (chan))
(def sub-2 (chan))
;subscribe subs to publisher
(sub publication "clojure" sub-1)
(sub publication "clojure" sub-2)
;start the sub loops
(go (while true (println "got on sub-1:: " (<! sub-1))))
(go (while true (println "got on sub-2:: " (<! sub-2))))
;publish
(>!! pub-ch {:topic "clojure" :k-1 "hello" })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment