-
-
Save anonymous/a7c47cd7b38c2e71a9bd 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
(require | |
'[clojure.core.async | |
:as | |
a | |
:refer | |
[>! <! >!! <!! go chan buffer close! thread alts! alts!! timeout]]) | |
(defn make-printer [] | |
(println "starting printer") | |
(let [in-chan (chan) off-chan (chan)] | |
(go-loop | |
[] | |
(let [[v ch] (alts! [off-chan in-chan])] | |
(if (= ch off-chan) | |
(do | |
(println (str "Stopping... msg: " v)) | |
(close! in-chan) | |
(close! off-chan) | |
(println "Stopped")) | |
(do (println (str "Input: " v)) (recur))))) | |
{:in in-chan, | |
:off off-chan, | |
:stop (fn stop! [] (>!! off-chan "turn off please")), | |
:send (fn send! [msg] (>!! in-chan msg))})) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment