Skip to content

Instantly share code, notes, and snippets.

Created January 10, 2014 02:26
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/8345977 to your computer and use it in GitHub Desktop.
Save anonymous/8345977 to your computer and use it in GitHub Desktop.
(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