Last active
May 19, 2021 19:06
-
-
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.
This file contains hidden or 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
(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