Skip to content

Instantly share code, notes, and snippets.

@2torus
Last active May 19, 2021 19:06
Show Gist options
  • Save 2torus/c406a935f283b4394a6c7cc4d2194720 to your computer and use it in GitHub Desktop.
Save 2torus/c406a935f283b4394a6c7cc4d2194720 to your computer and use it in GitHub Desktop.
Print channel, a channel that prints whatever is in the input and puts it back to output.
(require '[clojure.core.async :refer [chan, go, <!, >!, >!!, <!!]])
;=> nil
(defn print-channel
[channel-msg in]
(let [out (chan 1)]
(go (let [msg (<! in)]
((println channel-msg msg)
(>! out msg))))
out
))
(def in (chan))
(def out (print-channel "in-channel message: " in))
(>!! in "hello")
; => true
; in-channel message: hello
(<!! out)
; => "hello"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment