   [fn]
   (->ChanFun (async/chan) fn))
 
-(defmacro with-refresh-event-go-loop! [[event-hub] & body]
-  `(do ~@body
-       (async/put! (deref (:command-ch ~event-hub)) :refresh)))
+(defmacro with-issuing-event-go-loop-command! [[event-hub command] & body]
+  `(let [command-ch# (deref (:command-ch ~event-hub))]
+     ~@body
+     (when command-ch#
+       (async/put! command-ch# ~command))))
 
 (defn register-block-event
   ([fn-name fn]
    (register-block-event *event-hub* fn-name fn))
   ([event-hub fn-name fn]
-   (with-refresh-event-go-loop! [event-hub]
+   (with-issuing-event-go-loop-command! [event-hub :refresh]
      (swap! (:block-event-handlers event-hub) assoc fn-name fn))))
 
 (defn unregister-block-event
   ([fn-name]
    (unregister-block-event *event-hub* fn-name))
   ([event-hub fn-name]
-   (with-refresh-event-go-loop! [event-hub]
+   (with-issuing-event-go-loop-command! [event-hub :refresh]
      (swap! (:block-event-handlers event-hub) dissoc fn-name))))
 
 (defn- %unregister-event
   [event-hub id k]
-   (let [ref-m (k event-hub)]
-    (with-refresh-event-go-loop! [event-hub]
-      (when-let [existing (get (deref ref-m) id)]
-        (async/close! (:ch existing))
-        (swap! ref-m dissoc id)))))
+  (let [ref-m (k event-hub)]
+    (with-issuing-event-go-loop-command! [event-hub :refresh]
+      (swap! ref-m dissoc id))))
 
 (defn- %register-event
   [event-hub id fn k]
   (let [ref-m (k event-hub)]
-    (with-refresh-event-go-loop! [event-hub]
-      (when-let [existing (get (deref ref-m) id)]
-        (async/close! (:ch existing)))
+    (with-issuing-event-go-loop-command! [event-hub :refresh]
       (swap! ref-m assoc id (make-chan-fun fn)))))
 
 (defn register-tx-event

  [event-hub]
  (letfn [(%get-all-chans [k]
            (map :ch (vals (deref (k event-hub)))))]
    `[(:command-ch ~event-hub)
      (:block-event-chan ~event-hub)
      ~@(%get-all-chans :tx-id->chan-fn-map)
      ~@(%get-all-chans :chaincode-id->chan-fn-map)]))



(defn make-event-hub [user peer]
  (->EventHub user peer (async/chan (async/sliding-buffer default-sliding-buffer-size))
              (atom nil) ;;(async/chan) ;; command ch
              ;; block event ch & handlers
              (atom nil) ;; (async/chan (async/sliding-buffer default-sliding-buffer-size))
              (atom {})  ;; block-event-handlers
              (atom {})  ;; tx-id->chan-fn-map
              (atom {})  ;; chaincode-id->chan-fn-map
              (atom nil) ;; event-go-loop
              (atom nil) ;; start-time
              (atom nil) ;; end-time
              (atom nil) ;; managed-channel
              ))

(def ^:dynamic *event-hub* nil)
