 (defn init
   "Initiates a tcp socket connection to the server"
   [host port]
+  (reset! pending-requests {})
   (reset! tcp-request-ch (chan 1000))
   (reset! tcp-responce-ch (chan 1000))
   (reset! client (connect-stream-to-core-async-channels

   (let [{:keys [b-a request-uuid]} (io-assoc-base entity-id key value)]
     (>!! @tcp-request-ch {:b-a b-a :request-uuid request-uuid :callback callback}))))


(defn io-dissoc
  ([^String entity-id key]

(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)))))

