 
 (defn wait-for-step-waiting [state]
   (let [step-status-ch (:step-status-channel @state)
-        result-ch      (:result-channel @state)
         result         (read-channel-or-time-out
                          (async/go
                            (loop []
-                             (let [[status ch] (async/alts! [step-status-ch result-ch])]
-                               (cond (= ch result-ch) (Exception. (str "Step already finished! " status))
-                                     (not= :waiting status) (recur)
-                                     :default nil)))))]
+                             (let [status (async/<! step-status-ch)]
+                               (if (not= :waiting status)
+                                 (recur)
+                                 nil)))))]
     (when (instance? Exception result)
       (throw result)))
   state)
 
 (defn execute-pipeline-step [state step]
+  (clear-channel (:step-status-channel @state))
   (let [future (future
                  (let [execute-step-result (lambdacd-core/execute-step {} (:ctx @state)
                                                                        step)]

    (swap! state #(assoc % :step-future future))
    state))

(defn start-wait-for-git-step [state & {:keys [ref ms-between-polls] :or {ms-between-polls 100
                                                                          ref              "refs/heads/master"}}]
  (execute-pipeline-step state (fn [_ ctx]
                                 (wait-for-git ctx (get-in @state [:git :remote]) :ref ref :ms-between-polls ms-between-polls))))


(defn start-clone-step [state ref cwd]

                    (wait-for-step-to-complete)
                    (wait-for-pipeline-state-to-have-seen-commit "master" "other commit")
                    (git-commit "commit while not waiting")
                    (start-wait-for-git-step :wait false)
                    (get-step-result))]
      (is (= :success (:status (step-result state))))
      (is (= (commit-hash-by-msg state "other commit") (:old-revision (step-result state))))
