                                            :priority true)]
                        (= c timeout)))]
     (loop [cnt 1]
-      (let [finished? (test-fun)]
-        (when debug? (println "cnt =" cnt "time =" (System/currentTimeMillis)))
-        (if finished?
-          finished?
-          (if (timed-out?)
-            false
+      (if (timed-out?)
+        false
+        (let [finished? (test-fun)]
+          (when debug? (println "cnt =" cnt "time =" (System/currentTimeMillis)))
+          (if finished?
+            finished?
             (do
               (a/<!! (a/timeout delay-ms))
               (recur (inc cnt)))))))))


  (fact "timeout when `test-fun` always returns logical false"
    (wait-for-condition (fn [] (rand-nth [nil false]))
                        :timeout-ms 70)
    => false)

  (fact "correct call count when `test-fun` always returns logical false"

          res (wait-for-condition (fn []
                                    (swap! cnt-atom inc)
                                    nil)
                                  :timeout-ms 70 ; make this test run fast
                                  )]
      [res @cnt-atom])
    => (just [false
              #(<= % 3)]))

  (fact "`:delay-ms` works"
    (let [cnt-atom (atom 0)
          res (wait-for-condition (fn []
                                    (swap! cnt-atom inc)
                                    nil)
                                  :timeout-ms 70 ; make this test run fast
                                  :delay-ms  100)]
      [res @cnt-atom])
    => [false 1]))
