Skip to content

Instantly share code, notes, and snippets.

@michalmarczyk
Created July 11, 2013 23:03
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michalmarczyk/5980097 to your computer and use it in GitHub Desktop.
Save michalmarczyk/5980097 to your computer and use it in GitHub Desktop.
;; 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