       (message-dispatch msg @messages-send-chan)
       (recur))))
 
-(go (while true
-      (let [msg (<! @messages-send-chan)]
-        (swap! message-send-log conj msg)
-        (chsk-send! (:id msg) (:message msg)))))
+(defn start-message-send-loop [messages-send-chan]
+  (go-loop []
+    (when-let [msg (<! messages-send-chan)]
+      (println (str "send message " msg))
+      (swap! message-send-log conj msg)
+      (chsk-send! (:id msg) (:message msg))
+      (recur))))
 
+;; TODO
+;; - component?
+;; - tests
 (defn stop! []
   (do
     (close! @messages-receive-chan)
+    (close! @messages-send-chan)
     (stop-http-server!)
     (stop-router!)))
 

  (do
    (reset! messages-receive-chan (chan))
    (start-message-loop @messages-receive-chan)
    (start-http-server!)
    (start-router! @messages-receive-chan)))

(defn -main
  [& args]

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Application
(defonce messages-receive-chan (atom nil))
(defonce messages-send-chan (atom nil))

(defn start-message-loop [messages-receive-chan]
  (go-loop []
