Skip to content

Instantly share code, notes, and snippets.

@tim-br
Created January 30, 2016 17:20
Show Gist options
  • Save tim-br/d9560ada0d78cee10163 to your computer and use it in GitHub Desktop.
Save tim-br/d9560ada0d78cee10163 to your computer and use it in GitHub Desktop.
(use 'clojure.core.async)
(def input-chan (chan))
(def our-pub (pub input-chan :msg-type))
(>!! input-chan {:msg-type :greeting :text "hello"})
(def output-chan (chan))
(sub our-pub :greeting output-chan)
(go-loop []
(let [{:keys [text nonce]} (<! output-chan)]
(println text)
(println nonce)
(recur)))
(>!! input-chan {:msg-type :greeting :text "hi"})
(>!! input-chan {:msg-type :yolo :text "fun" :nonce "i dont know"})
(sub our-pub :yolo output-chan)
(def publisher-chan (chan))
(def publisher (pub publisher-chan #(get % 0)))
(def my-output-chan (chan))
(sub publisher 22 my-output-chan)
(go-loop []
(let [fun (<! my-output-chan)]
(println "test ")
(println (get fun 1))
(recur)))
(>!! publisher-chan [22 "now of course"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment