Skip to content

Instantly share code, notes, and snippets.

@razum2um razum2um/gist:d3255595a481ceae5745 Secret
Last active Aug 29, 2015

Embed
What would you like to do?
;; converter below creates a chan and returns it
;; but go-loop itself creates a chan
;;
;; 1) is it memory safe?
;; 2) do I need to call `close!` on go-loop created channel?
user=> (def in (chan))
#'user/in
user=> (defn converter [ch-in] (let [ch-out (chan)] (go-loop [m (<! ch-in)] (if m (>! ch-out (inc m)) (close! ch-out))) ch-out))
#'user/converter
user=> (def out (converter in))
#'user/out
user=> (async/thread (prn "out: " (<!! out)))
#<ManyToManyChannel clojure.core.async.impl.channels.ManyToManyChannel@3dca9ec3>
user=> (>!! in 5)
true
"out: " 6
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.