Skip to content

Instantly share code, notes, and snippets.

Created December 22, 2015 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/e29755d17bafda438300 to your computer and use it in GitHub Desktop.
Save anonymous/e29755d17bafda438300 to your computer and use it in GitHub Desktop.
(defn m-dec [buf]
(io/decode utf-codec buf))
(defn channel-handler [ch]
(go-loop []
(let [ch-data (<! ch) ]
(try
(let [msg (m-dec ch-data)]
(println "->" msg)
(if (= msg "stop")
(throw (Exception. "my exception message"))))
(catch Exception e (prn "channel exception: " (.getMessage e))
(close! ch)
(prn "channel shutdown!")))
(if-not (= ch-data nil)
(recur)))))
(defn channel-new []
(let [ch (chan)]
(channel-handler ch) ch))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment