Skip to content

Commit

Permalink
Temp: debug taoensso#75
Browse files Browse the repository at this point in the history
  • Loading branch information
ptaoussanis committed Oct 6, 2014
1 parent 04d3c5a commit 9a82bf9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
4 changes: 2 additions & 2 deletions example-project/project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject com.taoensso.examples/sente "1.1.1-SNAPSHOT"
(defproject com.taoensso.examples.debug/sente "1.1.1-SNAPSHOT"
:description "Sente, reference web-app example project"
:url "https://github.com/ptaoussanis/sente"
:license {:name "Eclipse Public License"
Expand All @@ -16,7 +16,7 @@
[org.clojure/clojurescript "0.0-2322"]
[org.clojure/core.async "0.1.338.0-5c5012-alpha"]
;;
[com.taoensso/sente "1.1.1-SNAPSHOT"] ; <--- Sente
[com.taoensso.debug/sente "1.1.1-SNAPSHOT"] ; <--- Sente
[com.taoensso/timbre "3.3.1"]
;;
[http-kit "2.1.19"] ; <--- http-kit (currently required)
Expand Down
6 changes: 4 additions & 2 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject com.taoensso/sente "1.1.1-SNAPSHOT"
(defproject com.taoensso.debug/sente "1.1.1-SNAPSHOT"
:author "Peter Taoussanis <https://www.taoensso.com>"
:description "Clojure channel sockets library"
:url "https://github.com/ptaoussanis/sente"
Expand All @@ -17,7 +17,9 @@
[org.clojure/tools.reader "0.8.8"]
[com.taoensso/encore "1.9.1"]
[com.taoensso/timbre "3.3.1"]
[http-kit "2.1.19"]]
[http-kit "2.1.19"]
[cider/cider-nrepl "0.7.0"] ; TODO Debugging #75
]

;; :plugins
;; [[com.keminglabs/cljx "0.4.0"]
Expand Down
22 changes: 21 additions & 1 deletion src/taoensso/sente.cljx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
#+clj (timbre/set-level! level)
#+cljs (reset! encore/logging-level level))

;; (set-logging-level! :trace) ; For debugging
(set-logging-level! :trace) ; For debugging

;;;; Ajax

Expand Down Expand Up @@ -307,15 +307,29 @@
connected-uids_ (atom {:ws #{} :ajax #{} :any #{}})
send-buffers_ (atom {:ws {} :ajax {}}) ; {<uid> [<buffered-evs> <#{ev-uuids}>]}

_ (add-watch conns_ ::conns-trace
(fn [_ _ old new]
(when (not= old new) (tracef "conns_ change: %s" (str new)))))

_ (add-watch connected-uids_ ::connected-uids-trace
(fn [_ _ old new]
(when (not= old new) (tracef "connected-uids_ change: %s" (str new)))))

connect-uid!
(fn [type uid]
(let [newly-connected?
(encore/swap-in! connected-uids_ []
(fn [{:keys [ws ajax any] :as old-m}]
(assert (set? ws))
(assert (set? ajax))
(assert (set? any))
(let [new-m
(case type
:ws {:ws (conj ws uid) :ajax ajax :any (conj any uid)}
:ajax {:ws ws :ajax (conj ajax uid) :any (conj any uid)})]
(assert (set? (:ws new-m)))
(assert (set? (:ajax new-m)))
(assert (set? (:any new-m)))
(encore/swapped new-m
(let [old-any (:any old-m)
new-any (:any new-m)]
Expand All @@ -329,6 +343,9 @@
(let [newly-disconnected?
(encore/swap-in! connected-uids_ []
(fn [{:keys [ws ajax any] :as old-m}]
(assert (set? ws))
(assert (set? ajax))
(assert (set? any))
(let [conns' @conns_
any-ws-clients? (contains? (:ws conns') uid)
any-ajax-clients? (contains? (:ajax conns') uid)
Expand All @@ -338,6 +355,9 @@
{:ws (if any-ws-clients? (conj ws uid) (disj ws uid))
:ajax (if any-ajax-clients? (conj ajax uid) (disj ajax uid))
:any (if any-clients? (conj any uid) (disj any uid))}]
(assert (set? (:ws new-m)))
(assert (set? (:ajax new-m)))
(assert (set? (:any new-m)))
(encore/swapped new-m
(let [old-any (:any old-m)
new-any (:any new-m)]
Expand Down

0 comments on commit 9a82bf9

Please sign in to comment.