Sign in

    moonbitstack/moonzero/breaker does not have a README file

    Unavailable

    pub suberror Unavailable

    Raised by Breaker::run for a call the throttle shed (← go-zero's ErrServiceUnavailable).

    Breaker

    pub struct Breaker {
    core :
    Breaker

    clock :
    Clock

    roll : () -> Double
    }

    Google SRE's client-side throttling breaker (← go-zero's googleBreaker).

    The algorithm is moonward's Breaker; this binds it to a Clock and a source of draws, the shape go-zero's breaker has, so a call site asks with no arguments. go-zero's constants are moonward's preset sre.

    Breaker::allow

    fn Breaker::allow(self : Breaker) -> Promise?

    Ask to make one call. Some promise means it may proceed and the caller settles the promise when it finishes; None means the throttle shed it.

    Breaker::drop_ratio

    fn Breaker::drop_ratio(self : Breaker) -> Double

    The fraction of new calls the breaker is shedding now, zero while healthy.

    Breaker::new

    fn Breaker::new(clock :
    Clock
    , rand? : () -> Double, buckets? : Int, bucket_ms? : Int64) -> Breaker

    A breaker over a buckets × bucket_ms window (go-zero's ten seconds in forty slices by default) reading time from clock. rand supplies the shed roll as a draw from [0, 1); without it the breaker draws from a system-seeded generator.

    Breaker::run

    fn[T] Breaker::run(self : Breaker, req : () -> T raise) -> T raise

    Run req under the breaker (← go-zero's Breaker.Do): a shed call raises Unavailable and req never runs; a raise from req counts as a failure.

    Promise

    The receipt for an admitted call (← go-zero's breaker.Promise).

    Promise::accept

    fn Promise::accept(self : Promise) -> Unit

    Promise::reject

    fn Promise::reject(self : Promise) -> Unit

    Source Files