Created
September 24, 2015 16:09
-
-
Save sonwh98/a5d34e47577bcd333eaf to your computer and use it in GitHub Desktop.
sub pub blocks subscriber from recieving messages when there is more than one subscriber to a topic
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
(require-macros '[cljs.core.async.macros :refer [go go-loop]]) | |
(require '[cljs.core.async :refer [put! <! >! chan pub sub unsub]]) | |
(defonce message-bus (chan)) | |
(defonce message-publication (pub message-bus (fn [msg] | |
(if (vector? msg) | |
(first msg) | |
:no-topic)))) | |
(def s1 (chan)) | |
(def s2 (chan)) | |
(sub message-publication :foo s1) | |
(go (while true (println "s1 " (<! s1)))) | |
(put! message-bus [:foo "bar"]) ;works as expected | |
(sub message-publication :foo s2) ;blocks s1 from recieving messages | |
(put! message-bus [:foo "bar"]) ;s1 cannot recieve this message | |
(go (while true (println "s2 " (<! s2)))) ; unblocks s1; both s1 and s2 can recieve messages |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment