             [clojure.core.async :refer [go chan close! timeout <!! >!! <! >!]]
             [clj-ravendb.responses :as res]))
 
+(def ^:dynamic *debug* false)
+(defmacro debug-do [& body]
+  (when *debug*
+    `(do ~@body)))
+
 (def not-nil? (complement nil?))
 
 (defn- post-req
   [{:keys [url body]}]
-  (println "Sending HTTP POST to" url "with JSON body " body)
+  (debug-do (println "Sending HTTP POST to" url "with JSON body " body))
   (client/post url {:body body :as :json-string-keys}))
 
 (defn- put-req
   [{:keys [url body]}]
-  (println "Sending HTTP PUT to" url "with JSON body " body)
+  (debug-do (println "Sending HTTP PUT to" url "with JSON body " body))
   (client/put url {:body body :as :json-string-keys}))
 
 (defn- get-req
   [{:keys [url]}]
-  (println "Sending HTTP GET to" url)
+  (debug-do (println "Sending HTTP GET to" url))
   (client/get url {:as :json-string-keys}))
 
 (defn- is-valid-client?

   (let [fragments (list url "Databases" database)
         address (clojure.string/join "/" fragments)
         load-replications (fn []
                             (println "Loading replication destinations from" address)
                             (:results (res/load-replications (get-req (req/load-replications address)))))
         replications (if replicated? 
                        (load-replications)

                   (go (>! channel latest)))
                 (if @keep-watching? 
                   (do 
                     (debug-do (println "Waiting" wait "ms until next 'watch'"))
                     (Thread/sleep wait)
                     (recur latest))))))]
     {:channel channel 
      :stop (fn []
              (debug-do (println "Closing channel" channel "and trying to end future" f))
              (reset! keep-watching? false)
              (close! channel))})))

