Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(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)
(assert (= (ClosedState. default-policy 0) @cb))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment