Errors
Execute() returns your function’s result and error untouched, except when the
breaker refuses to run it:
| Error | Returned when |
|---|---|
fluxgo.ErrOpenState | The circuit is Open and the request is rejected immediately |
fluxgo.ErrTooManyRequests | The circuit is Half-Open and the HalfOpenMaxRequests probe quota is already used |
Both are the same sentinels as in gobreaker, and are meant to be tested with
errors.Is.
res, err := cb.Execute(func() (interface{}, error) { return callDownstream()})
switch {case errors.Is(err, fluxgo.ErrOpenState): return fallback() // fast reject, the downstream was not calledcase errors.Is(err, fluxgo.ErrTooManyRequests): return fallback() // a probe is already in flightcase err != nil: return nil, err // the downstream's own error}Fast reject cost
Section titled “Fast reject cost”An Open circuit rejects in about 57 ns with zero allocations, so keeping a failing dependency behind the breaker is cheap. See Performance.
Slow calls are not errors
Section titled “Slow calls are not errors”A request classified as degraded counts as a failure internally only. Your caller still receives the original result and error.