                        (sel1 container :#game-status))
 
     ;; main game loop
-    (go (loop []
-          (let [msg (<! in)]
-            (cond
-              (nil? msg)
-              (do
-                (close! control)
-                (close! card-sel)
-                (close! board-state)
-                (close! player-state)
-                (close! status-state)
-                (dom/set-html! container "")
-                (msg/error "Disconnected from server"))
-
-              (= msg heartbeat-resp)
-              (do (recur))
-
-              (instance? msg/GameStateMessage msg)
-              (do (go-game-state (:game msg) board-state player-state status-state)
-                (recur))
-
-              (instance? msg/GameFinishMessage msg)
-              (let [{:keys [game]} msg]
-                (>! board-state :disable)
-                (<! (go-game-summary container msg))
-                (close! board-state)
-                (close! player-state)
-                msg)
-
-              :else
-              (do (println "UNHANDLED MSG" msg)
-                  (recur))))))))
+    (go-loop []
+      (let [msg (<! in)]
+        (cond
+          (nil? msg)
+          (do
+            (close! control)
+            (close! card-sel)
+            (close! board-state)
+            (close! player-state)
+            (close! status-state)
+            (dom/set-html! container "")
+            (msg/error "Disconnected from server"))
+
+          (= msg heartbeat-resp)
+          (do (recur))
+
+          (instance? msg/GameStateMessage msg)
+          (do (go-game-state (:game msg) board-state player-state status-state)
+              (recur))
+
+          (instance? msg/GameFinishMessage msg)
+          (let [{:keys [game]} msg]
+            (>! board-state :disable)
+            (<! (go-game-summary container msg))
+            (close! board-state)
+            (close! player-state)
+            msg)
+
+          :else
+          (do (println "UNHANDLED MSG" msg)
+              (recur)))))))
 
 (defn run-game!
   [container game-id player-id]

            [dommy.template :refer [html->nodes]])
  (:require-macros
    [dommy.macros :refer [sel sel1 deftemplate node]]
    [cljs.core.async.macros :refer [go alt!]]
    [cljs.core.match.macros :refer [match]]))

(def heartbeat-interval 7500)

(defn go-emit-heartbeat
  "A go loop to regularly write heartbeat message on channel"
  [control out interval]
  (go-loop []
    (let [tick (timeout interval)]
      (match (alts! [control tick])
        [nil control] nil
        [_ tick] (do (>! out heartbeat-req)
                     (recur))))))

(defn go-game [container in out player-id]
  (let [control (chan) ;; TODO integrate further
