Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
;; for now, consumer starts producer
;; -- must make sure that output chan already on comm-chan before producer starts
(defn producer [comm-chan]
(go (loop []
(if-let [c (<! comm-chan)]
(do
(>! c (rand))
(>! comm-chan c)
(recur))
(println :done)))))
(defn consumer []
(let [comm-chan (chan 1)
c (chan 5)]
(>!! comm-chan c)
(producer comm-chan)
(go (dotimes [i 10]
(println (<! c)))
(close! comm-chan)
(println (<! c)))))
user> (consumer)
#<ManyToManyChannel clojure.core.async.impl.channels.ManyToManyChannel@39d88fef>
0.48858350508458315
0.5446136119220218
0.32582715261618633
0.16814828882683197
0.00485421830103927
0.37070944308345277
0.6165331723831634
0.28219642381915655
0.5014768991693602
0.9350411298635354
0.6912907965087149
:done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.