             [clj-time.core :as time]
             [clj-time.local :as local-time]
             [clojure.core.async :as async :refer [go go-loop put! <!! alts! <! >!]]))
-
-(defn- collect-result [cs]
-  (let [[result c] (async/alts!! cs)]
-    @result))
-
-(defmacro with-channels [binding & body]
-  `(let [~(first binding) (repeatedly ~(second binding) async/chan)
-         ~'result (do ~@body)]
-    (dorun ~'result) ;Lazy results must be evaluated before channels are closed
-    (doseq [~'c ~(first binding)] (async/close! ~'c))
-    ~'result))
-
-(defn- run-parallel-and-collect-results [function times]
-  (with-channels [cs times]
-    (let [ps (map vector (iterate inc 0) cs)]
-      (doseq [[i c] ps]
-        (go (>! c (function i))))
-      (repeatedly times (partial collect-result cs)))))
-
-(defn- collect-result-and-run-next [cs run]
-  (let [[result c] (async/alts!! cs)
-        ret @result]
-    (go (>! c (run)))
-    ret))
 
 (defprotocol RunnerProtocol
   (continue-run? [runner current-time i])

  (continue-run? [_ _ i] (< i requests))
  (runner-info [_] (str "requests " requests)))

(defn- run-scenarios-in-parallel [scenario-runners parallel-count runner]
    (let [cs (repeatedly parallel-count async/chan)
          scenario-start (local-time/local-now)
          ps (map vector (iterate inc 0) cs)
          results (async/chan)]
      (doseq [[i c] ps]
        (go (>! c ((nth scenario-runners i)))))
      (let [count-c (go-loop [i 0]
                      (let [[result c] (async/alts! cs)]
                        (async/put! c ((nth scenario-runners (+ i parallel-count))))
                        (async/put! results result)
                      (if (continue-run? runner scenario-start i)
                        (recur (inc i))
                        i)))]
        (repeatedly (async/<!! count-c) (fn []  @(async/<!! results))))))

(defn- now [] (System/currentTimeMillis))

(defn- async-http-request [url user-id callback]

(defn- request-result [id request-name success start]
  {:id id :name request-name :result success :start start :end (now)})

(defn async-function-with-timeout [request timeout user-id result-channel]
  (let [start    (now)
        response (async/chan)
        function (memoize (request-fn request))]
    (go
