Permalink
Browse files

Fixed a bug in connection close. Another remains in the on-close call…

…back
  • Loading branch information...
1 parent 8406ab2 commit a46016f7f3658d93243150d7995356de4badf926 @andrewvc committed Jul 19, 2012
Showing with 14 additions and 11 deletions.
  1. +5 −2 example/example.clj
  2. +9 −9 src/noir_async/core.clj
View
@@ -17,12 +17,15 @@
(async-push conn {:status 200 :chunked true})
(async-push conn "chunk one")
(async-push conn "chunk two")
+ (on-close conn (fn [_] (println "CLOSED IT")))
(close conn))
(defn start-server [& m]
(let [mode (keyword (or (first m) :dev))
- port (Integer. (get (System/getenv) "PORT" "3000"))
+ port (Integer. (get (System/getenv) "PORT" "3502"))
noir-handler (nr-server/gen-handler {:mode mode})]
(start-http-server
(wrap-ring-handler noir-handler)
- {:port port :websocket true})))
+ {:port port :websocket true})))
+
+
@@ -80,20 +80,20 @@
(defn close
"Closes the connection. No more data can be sent / received after this"
[conn]
- (if-let [req-ch (:request-channel conn)]
- (if (lc/channel? req-ch)
- (lc/close req-ch)
- (async-push conn {:status 500 :body "Internal Error. Attempted explicit connection close on non-stream in noir-sync"})))
- (when-let [resp-ch @(:response-channel conn)] (lc/close resp-ch)))
+ (when-let [resp-ch @(:response-channel conn)]
+ (lc/close resp-ch))
+ (when-let [req-ch (:request-channel conn)]
+ (when (lc/channel? req-ch) (lc/close req-ch))))
(defn on-close
"Sets a callback to handle a closed connection.
Callback takes no arguments."
- [{:keys [request-channel]} handler]
- ;; We distinguish between Plain HTTP Channels (result channels)
- ;; and more socket oriented spliced ones
+ [{:keys [request-channel response-channel]} handler]
(if (lc/channel? request-channel)
- (lc/on-closed request-channel handler)))
+ (lc/on-closed request-channel handler)
+ (lc/on-realized request-channel
+ #(lc/on-closed (:body %) handler)
+ #(throw %))))
(defn on-receive
"Sets a callback to handle websocket messages.

0 comments on commit a46016f

Please sign in to comment.