breaker

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 10, 2023 License: Apache-2.0, MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrServiceUnavailable = errors.New("circuit breaker is open")

ErrServiceUnavailable is returned when the Breaker state is open.

Functions

func MinInt

func MinInt(a, b int) int

MinInt returns the smaller one of a and b.

Types

type Acceptable

type Acceptable func(err error) bool

Acceptable is the func to check if the error can be accepted.

type Breaker

type Breaker interface {
	// Name returns the name of the Breaker.
	Name() string

	// Allow checks if the request is allowed.
	// If allowed, a promise will be returned, the caller needs to call promise.Accept()
	// on success, or call promise.Reject() on failure.
	// If not allow, ErrServiceUnavailable will be returned.
	Allow() (Promise, error)
}

A Breaker represents a circuit breaker.

func NewBreaker

func NewBreaker(opts ...Option) Breaker

NewBreaker returns a Breaker object. opts can be used to customize the Breaker.

type Option

type Option func(breaker *circuitBreaker)

Option defines the method to customize a Breaker.

func WithName

func WithName(name string) Option

WithName returns a function to set the name of a Breaker.

type Promise

type Promise interface {
	// Accept tells the Breaker that the call is successful.
	Accept()
	// Reject tells the Breaker that the call is failed.
	Reject(reason string)
}

Promise interface defines the callbacks that returned by Breaker.Allow.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL