     (.recvBytes async-sock callback)
     nil))
 
+(defn- close!-impl
+  [sock closed]
+  (swap! closed (fn [closed]
+                  (if-not closed
+                    (do
+                      (nn/close! sock)
+                      (not closed))
+                    closed))))
+
+
 (deftype NanomsgWriteChannel [sock closed]
   protocols/WritePort
   (put! [_ value fn1-handler]


  protocols/Channel
  (close! [_]
    (swap! closed (fn [closed]
                    (if-not closed
                      (do
                        (nn/close! sock)
                        (not closed))
                      closed)))))

(defn chan
  "Channel constructor. Returns a core.async compatible


  protocols/Channel
  (close! [_]
    (close!-impl sock closed)))

(deftype NanomsgReadChannel [sock closed]
  protocols/ReadPort
