         :else (throw (Exception. (str "Callback of type " (type callback) " not supported")))))
 
 (defn start-tcp-responce-async-loop [client]
-  (go (loop []
-        (let [callback (<! @tcp-responce-ch)
+  (thread (loop []
+        (let [callback (<!! @tcp-responce-ch)
               stream-in-ch (:in @client)]
           (if-not (nil? stream-in-ch)
-            (let [responce (<! stream-in-ch)
+            (let [responce (<!! stream-in-ch)
+                  _ (println "got responce" responce)
                   responce (clojure.walk/keywordize-keys (cheshire/decode (String. (byte-array responce))))
                   request-uuid (keyword (get responce :request-uuid))
                   callback (get @pending-requests request-uuid)]


(defn- io-get-entity-as-of-base [^String entity-id timestamp]
  (let [{:keys [header-bytes request-uuid]} (header-bytes -127)
        entity-id-length (byte-array [(count entity-id)])
        entity-id-bytes (.getBytes entity-id)
        timestamp (.getBytes (str timestamp))]
    {:b-a (byte-array (concat header-bytes entity-id-length entity-id-bytes timestamp))
     :request-uuid request-uuid}))

(def tcp-request-ch (atom (chan 1000)))

(defn start-tcp-request-async-loop [client]
  (thread (loop []
        (let [{:keys [callback b-a request-uuid]} (<!! @tcp-request-ch)
              request-uuid (keyword request-uuid)
              stream-out-ch (:out @client)
              send-result (if stream-out-ch
                            (>!! stream-out-ch b-a)
                            false)]
          ;add to pending-requests
          (swap! pending-requests assoc request-uuid callback)
          (if send-result
            ;schedule a "take" from the socket
            (do
              (println "scheduling a take...")
              (>!! @tcp-responce-ch callback))
            (dispatch-to-callback callback {:error ":out socket channel closed, no data sent"}))
          (recur)))))

