-
-
Save razum2um/d3255595a481ceae5745 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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