2020-07-26 17:09:05 +08:00
|
|
|
package breaker
|
|
|
|
|
2024-04-18 18:00:17 +08:00
|
|
|
import "context"
|
|
|
|
|
2023-10-06 23:41:09 +08:00
|
|
|
const nopBreakerName = "nopBreaker"
|
2020-07-26 17:09:05 +08:00
|
|
|
|
2023-10-06 23:41:09 +08:00
|
|
|
type nopBreaker struct{}
|
2020-07-26 17:09:05 +08:00
|
|
|
|
2024-02-25 11:24:44 +08:00
|
|
|
// NopBreaker returns a breaker that never trigger breaker circuit.
|
|
|
|
func NopBreaker() Breaker {
|
2023-10-06 23:41:09 +08:00
|
|
|
return nopBreaker{}
|
2020-07-26 17:09:05 +08:00
|
|
|
}
|
|
|
|
|
2023-10-06 23:41:09 +08:00
|
|
|
func (b nopBreaker) Name() string {
|
|
|
|
return nopBreakerName
|
2020-07-26 17:09:05 +08:00
|
|
|
}
|
|
|
|
|
2023-10-06 23:41:09 +08:00
|
|
|
func (b nopBreaker) Allow() (Promise, error) {
|
2020-07-26 17:09:05 +08:00
|
|
|
return nopPromise{}, nil
|
|
|
|
}
|
|
|
|
|
2024-04-18 18:00:17 +08:00
|
|
|
func (b nopBreaker) AllowCtx(_ context.Context) (Promise, error) {
|
|
|
|
return nopPromise{}, nil
|
|
|
|
}
|
|
|
|
|
2023-10-06 23:41:09 +08:00
|
|
|
func (b nopBreaker) Do(req func() error) error {
|
2020-07-26 17:09:05 +08:00
|
|
|
return req()
|
|
|
|
}
|
|
|
|
|
2024-04-18 18:00:17 +08:00
|
|
|
func (b nopBreaker) DoCtx(_ context.Context, req func() error) error {
|
|
|
|
return req()
|
|
|
|
}
|
|
|
|
|
2023-10-06 23:41:09 +08:00
|
|
|
func (b nopBreaker) DoWithAcceptable(req func() error, _ Acceptable) error {
|
2020-07-26 17:09:05 +08:00
|
|
|
return req()
|
|
|
|
}
|
|
|
|
|
2024-04-18 18:00:17 +08:00
|
|
|
func (b nopBreaker) DoWithAcceptableCtx(_ context.Context, req func() error, _ Acceptable) error {
|
|
|
|
return req()
|
|
|
|
}
|
|
|
|
|
2024-02-15 20:29:24 +08:00
|
|
|
func (b nopBreaker) DoWithFallback(req func() error, _ Fallback) error {
|
2020-07-26 17:09:05 +08:00
|
|
|
return req()
|
|
|
|
}
|
|
|
|
|
2024-04-18 18:00:17 +08:00
|
|
|
func (b nopBreaker) DoWithFallbackCtx(_ context.Context, req func() error, _ Fallback) error {
|
|
|
|
return req()
|
|
|
|
}
|
|
|
|
|
2024-02-15 20:29:24 +08:00
|
|
|
func (b nopBreaker) DoWithFallbackAcceptable(req func() error, _ Fallback, _ Acceptable) error {
|
2020-07-26 17:09:05 +08:00
|
|
|
return req()
|
|
|
|
}
|
|
|
|
|
2024-04-18 18:00:17 +08:00
|
|
|
func (b nopBreaker) DoWithFallbackAcceptableCtx(_ context.Context, req func() error,
|
|
|
|
_ Fallback, _ Acceptable) error {
|
|
|
|
return req()
|
|
|
|
}
|
|
|
|
|
2020-07-26 17:09:05 +08:00
|
|
|
type nopPromise struct{}
|
|
|
|
|
|
|
|
func (p nopPromise) Accept() {
|
|
|
|
}
|
|
|
|
|
2022-12-11 00:41:50 +08:00
|
|
|
func (p nopPromise) Reject(_ string) {
|
2020-07-26 17:09:05 +08:00
|
|
|
}
|