Skip to content

Instantly share code, notes, and snippets.

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

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=> (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=> (def out (converter in))
user=> (async/thread (prn "out: " (<!! out)))
#<ManyToManyChannel clojure.core.async.impl.channels.ManyToManyChannel@3dca9ec3>
user=> (>!! in 5)
"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.