Skip to content

Commit

Permalink
Revert "[Experimental] Client: send-fn support for arb channels as ti…
Browse files Browse the repository at this point in the history
…meout mechanism"

This reverts commit efad932.

Dubious about the value of this, even if it didn't involve a protocol dependency.
  • Loading branch information
ptaoussanis committed Aug 6, 2016
1 parent 9535510 commit b793db1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 33 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ The client will automatically initiate a WebSocket or repeating long-polling con
#### Client-side API

* `ch-recv` is a **core.async channel** that'll receive `event-msg`s
* `chsk-send!` is a `(fn [event & [?timeout ?cb-fn]])` for standard **client>server req>resp calls**
* `chsk-send!` is a `(fn [event & [?timeout-ms ?cb-fn]])` for standard **client>server req>resp calls**

#### Server-side API

Expand Down
48 changes: 16 additions & 32 deletions src/taoensso/sente.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -768,13 +768,11 @@
(defn chsk-send!
"Sends `[ev-id ev-?data :as event]`, returns true on apparent success."
([chsk ev] (chsk-send! chsk ev {}))
([chsk ev ?timeout ?cb] (chsk-send! chsk ev {:timeout ?timeout :cb ?cb}))
([chsk ev ?timeout-ms ?cb] (chsk-send! chsk ev {:timeout-ms ?timeout-ms
:cb ?cb}))
([chsk ev opts]
(let [;; For back compatibility:
?timeout (get opts :timeout (get opts :timeout-ms))
opts (assoc opts :timeout ?timeout)]
(tracef "Chsk send: (%s) %s" (assoc opts :cb (boolean (:cb opts))) ev)
(-chsk-send! chsk ev opts)))))
(tracef "Chsk send: (%s) %s" (assoc opts :cb (boolean (:cb opts))) ev)
(-chsk-send! chsk ev opts))))

#?(:cljs
(defn- chsk-send->closed! [?cb-fn]
Expand All @@ -783,12 +781,11 @@
false))

#?(:cljs
(defn- assert-send-args [x ?timeout ?cb]
(defn- assert-send-args [x ?timeout-ms ?cb]
(assert-event x)
(assert (or (and (nil? ?timeout) (nil? ?cb))
(or (enc/chan? ?timeout)
(enc/nat-int? ?timeout)))
(str "cb requires a timeout; timeout should be a +ive integer or channel: " ?timeout))
(assert (or (and (nil? ?timeout-ms) (nil? ?cb))
(and (enc/nat-int? ?timeout-ms)))
(str "cb requires a timeout; timeout-ms should be a +ive integer: " ?timeout-ms))
(assert (or (nil? ?cb) (ifn? ?cb) (enc/chan? ?cb))
(str "cb should be nil, an ifn, or a channel: " (type ?cb)))))

Expand Down Expand Up @@ -946,8 +943,8 @@
(-chsk-connect! chsk))

(-chsk-send! [chsk ev opts]
(let [{?timeout :timeout ?cb :cb :keys [flush?]} opts
_ (assert-send-args ev ?timeout ?cb)
(let [{?timeout-ms :timeout-ms ?cb :cb :keys [flush?]} opts
_ (assert-send-args ev ?timeout-ms ?cb)
?cb-fn (cb-chan-as-fn ?cb ev)]
(if-not (:open? @state_) ; Definitely closed
(chsk-send->closed! ?cb-fn)
Expand All @@ -958,15 +955,10 @@

(when-let [cb-uuid ?cb-uuid]
(reset-in! cbs-waiting_ [cb-uuid] (have ?cb-fn))
(when-let [timeout ?timeout]
(let [timeout-ch
(if (enc/chan? timeout)
timeout
(async/timeout (have enc/nat-int? timeout)))]
(go
(<! timeout-ch)
(when-let [timeout-ms ?timeout-ms]
(go (<! (async/timeout timeout-ms))
(when-let [cb-fn* (pull-unused-cb-fn! cbs-waiting_ ?cb-uuid)]
(cb-fn* :chsk/timeout))))))
(cb-fn* :chsk/timeout)))))

(try
(.send @socket_ ppstr)
Expand Down Expand Up @@ -1139,17 +1131,9 @@
(-chsk-connect! chsk))

(-chsk-send! [chsk ev opts]
(let [{?timeout :timeout ?cb :cb :keys [flush?]} opts
_ (assert-send-args ev ?timeout ?cb)
?timeout-ms
(when ?timeout
(if (enc/chan? ?timeout)
(throw
(ex-info "`chsk-send!` error: timeout channels only supported for WebSocket connections"
{}))
(have enc/nat-int? ?timeout)))
(let [{?timeout-ms :timeout-ms ?cb :cb :keys [flush?]} opts
_ (assert-send-args ev ?timeout-ms ?cb)
?cb-fn (cb-chan-as-fn ?cb ev)]

(if-not (:open? @state_) ; Definitely closed
(chsk-send->closed! ?cb-fn)

Expand Down Expand Up @@ -1371,7 +1355,7 @@
"Returns nil on failure, or a map with keys:
:ch-recv ; core.async channel to receive `event-msg`s (internal or from
; clients). May `put!` (inject) arbitrary `event`s to this channel.
:send-fn ; (fn [event & [?timeout ?cb-fn]]) for client>server send.
:send-fn ; (fn [event & [?timeout-ms ?cb-fn]]) for client>server send.
:state ; Watchable, read-only (atom {:type _ :open? _ :uid _ :csrf-token _}).
:chsk ; IChSocket implementer. You can usu. ignore this.
Expand Down

0 comments on commit b793db1

Please sign in to comment.