From 36ced2b5093cd091c695334facaf977546505488 Mon Sep 17 00:00:00 2001 From: Ziyang Hu Date: Mon, 1 Sep 2014 23:36:30 +0800 Subject: [PATCH 1/2] fix bad assertion --- src/com/keminglabs/zmq_async/core.clj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/com/keminglabs/zmq_async/core.clj b/src/com/keminglabs/zmq_async/core.clj index 13f9918..18b1f4a 100644 --- a/src/com/keminglabs/zmq_async/core.clj +++ b/src/com/keminglabs/zmq_async/core.clj @@ -157,9 +157,9 @@ Sends messages to complementary `zmq-looper` via provided `zmq-control-sock` (as ;;Relay a message from ZeroMQ socket to core.async channel. [:control [sock-id msg]] (let [out (get-in pairings [sock-id :out])] - (assert out) - ;;We have a contract with library consumers that they cannot give us channels that can block, so this >!! won't tie up the async looper. - (>!! out msg) + (when out + ;;We have a contract with library consumers that they cannot give us channels that can block, so this >!! won't tie up the async looper. + (>!! out msg)) (recur pairings)) ;;The control channel has been closed, close all ZMQ sockets and channels. From b11ab364f05a3b6dcb6e1fc81a9e919a5a87907e Mon Sep 17 00:00:00 2001 From: Ziyang Hu Date: Wed, 3 Sep 2014 10:25:00 +0800 Subject: [PATCH 2/2] added assertion for :in and :out channels --- src/com/keminglabs/zmq_async/core.clj | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/com/keminglabs/zmq_async/core.clj b/src/com/keminglabs/zmq_async/core.clj index 18b1f4a..eec9126 100644 --- a/src/com/keminglabs/zmq_async/core.clj +++ b/src/com/keminglabs/zmq_async/core.clj @@ -275,8 +275,13 @@ Accepts a map with the following keys: (when (and socket (or socket-type configurator)) (throw (IllegalArgumentException. "You can provide a ZeroMQ socket OR a socket-type and configurator, not both."))) - (when (and (nil? out) (nil? in)) - (throw (IllegalArgumentException. "You must provide at least one of :out and :in channels."))) + (cond + (#{:pair :req :rep :xreq :xrep :dealer :router :xpub :xsub} socket-type) + (assert (and in out) (str socket-type "socket requires both :in and :out channels")) + (#{:pub :push} socket-type) + (assert in (str socket-type "socket requires an :in channel")) + (#{:sub :pull} socket-type) + (assert out (str socket-type "socket requires an :out channel"))) (let [context (or context (doto automagic-context (initialize!)))