Created
January 10, 2014 02:26
-
-
Save anonymous/8345977 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
(defn ws-reject! [req] | |
(hk/with-channel req channel | |
(hk/send! channel (pr-str {:tag :closed})) | |
(hk/close channel))) | |
(defn ws-allow! [req] | |
(let [msg-chan (chan 100) | |
signal-chan (chan 1)] | |
(hk/with-channel req channel | |
(let [queue (tome/g-in [:server :http :queue])] | |
(hk/on-close channel (fn [status] | |
(close msg-chan) | |
(put! signal-chan {:tag :websocket-close | |
:status status}))) | |
(hk/on-receive | |
channel | |
(fn [msg] | |
(let [msg (clojure.edn/read-string msg) | |
rslts (alts!! [authorized-chan msg] | |
:default :chan-full)] | |
(if (= rslt :chan-full) | |
(do (hk/send! channel (pr-str {:tag :chan-full})) | |
(hk/close channel)) | |
)))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment