Skip to content

Commit 7eac6c5

Browse files
committed
deprecated sente/start-chsk-router-loop! replaced with sente/start-chsk-router!
1 parent bab4e80 commit 7eac6c5

File tree

2 files changed

+17
-33
lines changed

2 files changed

+17
-33
lines changed

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

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,35 +33,20 @@
3333
(def connected-uids connected-uids)) ; Watchable, read-only atom
3434

3535
(defn- event-msg-handler
36-
[{:as ev-msg :keys [ring-req event ?reply-fn]} _]
37-
(let [session (:session ring-req)
38-
[id data :as ev] event]
36+
[{:as ev-msg :keys [event ?reply-fn]}]
37+
(match event
38+
[:cmd/percolate params] (p/start-percolator params)
39+
[:cmd/query params] (do
40+
(log/info "Received query:" params)
41+
(let [res (p/query params)] ; TODO: put request msg on channel for async handling
42+
(chsk-send! (:uid params) [:tweet/prev-chunk res])))
43+
[:cmd/missing params] (put! c/tweet-missing-chan params)
44+
[:chsk/ws-ping params] () ; currently just do nothing with ping (no logging either)
45+
:else (do (log/info "Unmatched event:" event)
46+
(when-not (:dummy-reply-fn? (meta ?reply-fn))
47+
(?reply-fn {:umatched-event-as-echoed-from-from-server event})))))
3948

40-
(match [id data]
41-
;; TODO: Match your events here, reply when appropriate <...>
42-
43-
[:cmd/percolate params]
44-
(p/start-percolator params)
45-
46-
[:cmd/query params]
47-
(do
48-
(log/info "Received query:" params)
49-
(let [res (p/query params)]
50-
;(doseq [t res] (chsk-send! (:uid params) [:some/tweet (:_source t)]))
51-
(chsk-send! (:uid params) [:tweet/prev-chunk res])))
52-
53-
[:cmd/missing params]
54-
(put! c/tweet-missing-chan params)
55-
56-
[:chsk/ws-ping params]
57-
() ; currently just do nothing with ping (no logging either)
58-
59-
:else
60-
(do (log/info "Unmatched event:" ev)
61-
(when-not (:dummy-reply-fn? (meta ?reply-fn))
62-
(?reply-fn {:umatched-event-as-echoed-from-from-server ev}))))))
63-
64-
(defonce chsk-router (sente/start-chsk-router-loop! event-msg-handler ch-chsk))
49+
(defonce chsk-router (sente/start-chsk-router! ch-chsk event-msg-handler))
6550

6651
;; loop for matching connected clients with percolation matches and delivering those on the appropriate socket
6752
(go

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@
5252
(start-percolator)
5353
(load-prev)))
5454

55-
(defn- event-handler [[id data :as ev] _]
56-
(match [id data]
55+
(defn- event-handler [{:keys [event]}]
56+
(match event
5757
[:chsk/state {:first-open? true}] (do (print "Socket established!") (start-search))
5858
[:chsk/state new-state] (print "Chsk state change:" new-state)
5959
[:chsk/recv payload]
@@ -64,10 +64,9 @@
6464
[:tweet/prev-chunk prev-chunk] (do (put! c/prev-chunks-chan prev-chunk) (load-prev))
6565
[:stats/users-count uc] (put! c/user-count-chan uc)
6666
[:stats/total-tweet-count ttc] (put! c/total-tweets-count-chan ttc)))
67-
:else (print "Unmatched event: %s" ev)))
67+
:else (print "Unmatched event: %s" event)))
6868

69-
(defonce chsk-router
70-
(sente/start-chsk-router-loop! event-handler ch-chsk))
69+
(defonce chsk-router (sente/start-chsk-router! ch-chsk event-handler))
7170

7271
; loop for sending messages about missing tweet to server
7372
(go-loop []

0 commit comments

Comments
 (0)