Last active
August 29, 2015 14:11
-
-
Save raspasov/81c678961b6292eebe04 to your computer and use it in GitHub Desktop.
clojure core.async pub/sub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;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