(with-channel req ch-name & [opts & body])
Extracts the websocket from the request and binds it to 'ch-name' in the body Arguments: req - (required) HTTP-kit request map ch-name - (required) variable to bind the channel to in the body opts - (optional) map to configure reading/writing channels :read-ch - (optional) (possibly buffered) channel to use for reading the websocket :write-ch - (optional) (possibly buffered) channel to use for writing to the websocket :format - (optional) data format to use on the channel, (at the moment) either :edn (default), :json, :json-kw, :transit-json, or :str. (and any other options your formatter needs)
Usage: (require '[clojure.core.async :as a])
(with-channel req the-ws (a/go-loop [] (when-let [msg (a/<! the-ws)] (println msg) (recur))))
(with-channel req the-ws {:read-ch (a/chan (a/sliding-buffer 10)) :write-ch (a/chan (a/dropping-buffer 5))}
(go-loop [] (when-let [msg (<! the-ws)] (println msg) (recur))))
Extracts the websocket from the request and binds it to 'ch-name' in the body Arguments: req - (required) HTTP-kit request map ch-name - (required) variable to bind the channel to in the body opts - (optional) map to configure reading/writing channels :read-ch - (optional) (possibly buffered) channel to use for reading the websocket :write-ch - (optional) (possibly buffered) channel to use for writing to the websocket :format - (optional) data format to use on the channel, (at the moment) either :edn (default), :json, :json-kw, :transit-json, or :str. (and any other options your formatter needs) Usage: (require '[clojure.core.async :as a]) (with-channel req the-ws (a/go-loop [] (when-let [msg (a/<! the-ws)] (println msg) (recur)))) (with-channel req the-ws {:read-ch (a/chan (a/sliding-buffer 10)) :write-ch (a/chan (a/dropping-buffer 5))} (go-loop [] (when-let [msg (<! the-ws)] (println msg) (recur))))
(wrap-websocket-handler handler & [opts])
Middleware that puts a :ws-channel key on the request map for websocket requests.
Arguments:
handler - (required) Ring-compatible handler
opts - (optional) Options for the WebSocket channel - same options as for with-channel
Middleware that puts a :ws-channel key on the request map for websocket requests. Arguments: handler - (required) Ring-compatible handler opts - (optional) Options for the WebSocket channel - same options as for `with-channel`
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close