nopbreaker.go 813 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package breaker
  2. const noOpBreakerName = "nopBreaker"
  3. type noOpBreaker struct{}
  4. func newNoOpBreaker() Breaker {
  5. return noOpBreaker{}
  6. }
  7. func (b noOpBreaker) Name() string {
  8. return noOpBreakerName
  9. }
  10. func (b noOpBreaker) Allow() (Promise, error) {
  11. return nopPromise{}, nil
  12. }
  13. func (b noOpBreaker) Do(req func() error) error {
  14. return req()
  15. }
  16. func (b noOpBreaker) DoWithAcceptable(req func() error, acceptable Acceptable) error {
  17. return req()
  18. }
  19. func (b noOpBreaker) DoWithFallback(req func() error, fallback func(err error) error) error {
  20. return req()
  21. }
  22. func (b noOpBreaker) DoWithFallbackAcceptable(req func() error, fallback func(err error) error,
  23. acceptable Acceptable) error {
  24. return req()
  25. }
  26. type nopPromise struct{}
  27. func (p nopPromise) Accept() {
  28. }
  29. func (p nopPromise) Reject(reason string) {
  30. }