Skip to content

Commit

Permalink
make sure streaming response channel is closed when connection is closed
Browse files Browse the repository at this point in the history
  • Loading branch information
ztellman committed Sep 6, 2012
1 parent 3ac67b3 commit a312591
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/aleph/http/core.clj
Expand Up @@ -172,7 +172,13 @@

(defn expand-writes [f honor-keep-alive? ch]
(let [ch* (channel)
default-charset (options/charset)]
default-charset (options/charset)
current-stream (atom nil)]

(on-closed ch
#(when-let [stream @current-stream]
(close stream)))

(bridge-join ch "aleph.http.core/expand-writes"
(fn [m]
(let [{:keys [msg chunks write-callback]} (f m)
Expand All @@ -184,6 +190,8 @@
(close ch*)
true))]

(reset! current-stream chunks)

(if-not chunks

;; non-streaming response
Expand Down

0 comments on commit a312591

Please sign in to comment.