Skip to content

Instantly share code, notes, and snippets.

@krukow
Created May 5, 2010 08:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krukow/390535 to your computer and use it in GitHub Desktop.
Save krukow/390535 to your computer and use it in GitHub Desktop.
(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