Skip to content

Commit d82064b

Browse files
committed
Tear down resources when stopping communicator resources
According to comments from Peter Taoussanis: taoensso/sente#72 (comment)
1 parent 8ddf262 commit d82064b

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Clojure-Websockets/src/clj/birdwatch/communicator.clj

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
(chsk-send! (:uid res) [:tweet/prev-chunk (:result res)]))
6565
(recur)))
6666

67-
(defrecord Communicator [channels]
67+
(defrecord Communicator [channels chsk-router]
6868
component/Lifecycle
6969
(start [component]
7070
(log/info "Starting Communicator Component")
@@ -77,8 +77,12 @@
7777
(run-tweet-stats-loop send-fn connected-uids (:tweet-count channels))
7878
(run-missing-tweet-loop (:missing-tweet-found channels) send-fn)
7979
(run-query-results-loop (:query-results channels) send-fn)
80-
(assoc component :ajax-post-fn ajax-post-fn :ajax-get-or-ws-handshake-fn ajax-get-or-ws-handshake-fn)))
80+
(assoc component :ajax-post-fn ajax-post-fn
81+
:ajax-get-or-ws-handshake-fn ajax-get-or-ws-handshake-fn
82+
:chsk-router chsk-router)))
8183
(stop [component]
82-
(log/info "Stopping Persistence Component"))) ;; TODO: teardown
84+
(log/info "Stopping Communicator Component")
85+
(chsk-router) ;; stops router loop
86+
(assoc component :chsk-router nil)))
8387

8488
(defn new-communicator [] (map->Communicator {}))

0 commit comments

Comments
 (0)