Create a gist now

Instantly share code, notes, and snippets.

(def cb (make-circuit-breaker))
(def succ (wrap-with (constantly 42) cb))
(def fail (wrap-with (fn [] (throw (Exception.))) cb))
(dotimes [i 5]
(try (fail) (catch Exception e)))
(assert (= (ClosedState. default-policy 5) @cb))
(try (fail) (catch Exception e))
(assert (= (class (OpenState. default-policy 0)) (class @cb)))
(Thread/sleep 5000)
(succ)
(assert (= (ClosedState. default-policy 0) @cb))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment