add response-timeout option to immutant adapter (same as jetty adapter)

This commit is contained in:
Gered 2016-05-09 20:06:12 -04:00
parent 579945fbda
commit 37db9ce909
5 changed files with 29 additions and 10 deletions

View file

@ -12,7 +12,7 @@
[prismatic/dommy "1.1.0"] [prismatic/dommy "1.1.0"]
[gered/clj-browserchannel "0.3"] [gered/clj-browserchannel "0.3"]
[gered/clj-browserchannel-jetty-adapter "0.1.0"] [gered/clj-browserchannel-jetty-adapter "0.1.0"]
[gered/clj-browserchannel-immutant-adapter "0.0.1"] [gered/clj-browserchannel-immutant-adapter "0.0.2"]
[org.immutant/web "2.1.4"] [org.immutant/web "2.1.4"]
[environ "1.0.3"]] [environ "1.0.3"]]

View file

@ -58,7 +58,7 @@
(defn -main [& args] (defn -main [& args]
(if (env :dev) (pebble/set-options! :cache false)) (if (env :dev) (pebble/set-options! :cache false))
(run-jetty) ;(run-jetty)
;(run-immutant) (run-immutant)
) )

View file

@ -1,10 +1,14 @@
# clj-browserchannel-immutant-adapter # clj-browserchannel-immutant-adapter
Immutant async adapter for BrowserChannel Immutant async adapter for BrowserChannel.
See also: [clj-browserchannel][1] See also: [clj-browserchannel][1]
[1]:https://github.com/gered/clj-browserchannel [1]:https://github.com/gered/clj-browserchannel
## Leiningen
[gered/clj-browserchannel-immutant-adapter "0.0.1"]
## About ## About
Written by: Written by:

View file

@ -1,4 +1,4 @@
(defproject gered/clj-browserchannel-immutant-adapter "0.0.1" (defproject gered/clj-browserchannel-immutant-adapter "0.0.2"
:description "Immutant async adapter for BrowserChannel" :description "Immutant async adapter for BrowserChannel"
:dependencies [[gered/clj-browserchannel "0.3"]] :dependencies [[gered/clj-browserchannel "0.3"]]
:profiles {:provided :profiles {:provided

View file

@ -22,14 +22,22 @@
(defn wrap-immutant-async-adapter (defn wrap-immutant-async-adapter
"wraps the ring handler with an async adapter necessary for "wraps the ring handler with an async adapter necessary for
browserchannel sessions." browserchannel sessions.
[handler]
options available:
:response-timeout - Timeout after which the server will close the
connection. Specified in milliseconds, default
is 4 minutes which is the timeout period Google
uses."
[handler & [options]]
(fn [request] (fn [request]
(let [resp (handler request)] (let [resp (handler request)]
(if (= :http (:async resp)) (if (= :http (:async resp))
(iasync/as-channel (iasync/as-channel
request request
{:on-open {:timeout (get options :response-timeout (* 4 60 1000))
:on-open
(fn [channel] (fn [channel]
(let [reactor (:reactor resp) (let [reactor (:reactor resp)
emit (ImmutantResponse. channel)] emit (ImmutantResponse. channel)]
@ -44,8 +52,15 @@
use wrap-immutant-async-adapter instead and not use this function. use wrap-immutant-async-adapter instead and not use this function.
options is passed directly to immutant. see immutant.web/run options is passed directly to immutant. see immutant.web/run
for a description of the available options." for a description of the available options.
some additional options used by the async adapter are available:
:response-timeout - Timeout after which the server will close the
connection. Specified in milliseconds, default
is 4 minutes which is the timeout period Google
uses."
[handler options] [handler options]
(-> handler (-> handler
(wrap-immutant-async-adapter) (wrap-immutant-async-adapter options)
(iweb/run options))) (iweb/run options)))