diff --git a/src/clj/grub/core.clj b/src/clj/grub/core.clj index 8cbc156..f731c7b 100644 --- a/src/clj/grub/core.clj +++ b/src/clj/grub/core.clj @@ -62,9 +62,14 @@ (httpkit/with-channel request ws-channel (let [to-client (chan) from-client (chan) - new-states (chan (a/sliding-buffer 1))] + new-states (chan (a/sliding-buffer 1)) + on-close (fn [] + (a/unsub new-states-pub :new-state new-states) + (a/close! new-states) + (a/close! from-client) + (a/close! to-client))] (a/sub new-states-pub :new-state new-states) - (ws/add-connected-client! ws-channel to-client from-client) + (ws/add-connected-client! ws-channel to-client from-client on-close) (sync/make-server-agent to-client from-client new-states states))) (handler request)))) diff --git a/src/clj/grub/websocket.clj b/src/clj/grub/websocket.clj index f04c62f..5287206 100644 --- a/src/clj/grub/websocket.clj +++ b/src/clj/grub/websocket.clj @@ -22,11 +22,15 @@ received (t/read reader)] received)) -(defn add-connected-client! [ws-channel to from] +(defn add-connected-client! [ws-channel to from on-close] (println "Client connected:" (.toString ws-channel)) (a/go-loop [] (if-let [event (