Create a gist now

Instantly share code, notes, and snippets.

(ns net.higher-order.integration.circuit-breaker.states)
(deftype TransitionPolicy [fail-count timeout])
(defprotocol CircuitBreakerTransitions
"Transition functions for circuit-breaker states"
(proceed [s] "true if breaker should proceed with call in this state")
(on-success [s] "transition from s to this state after a successful call")
(on-error [s] "transition from s to this state after an unsuccessful call")
(on-before-call [s] "transition from s to this state before a call"))
(deftype ClosedState [policy fail-count] clojure.lang.IPersistentMap)
(deftype OpenState [policy time-stamp] clojure.lang.IPersistentMap)
(deftype InitialHalfOpenState [policy] clojure.lang.IPersistentMap)
(deftype PendingHalfOpenState [policy] clojure.lang.IPersistentMap)
(def #^{:private true}
abs-transitions
{:proceed (constantly false)
:on-success identity
:on-error identity
:on-before-call identity})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment