tile38/vendor/github.com/eapache/go-resiliency/breaker
tidwall 712da8aefa Updated Kafka client 2020-06-24 14:20:22 -07:00
..
README.md Updated Kafka client 2020-06-24 14:20:22 -07:00
breaker.go Refactor repository and build scripts 2019-11-18 10:33:15 -07:00

README.md

circuit-breaker

Build Status GoDoc Code of Conduct

The circuit-breaker resiliency pattern for golang.

Creating a breaker takes three parameters:

  • error threshold (for opening the breaker)
  • success threshold (for closing the breaker)
  • timeout (how long to keep the breaker open)
b := breaker.New(3, 1, 5*time.Second)

for {
	result := b.Run(func() error {
		// communicate with some external service and
		// return an error if the communication failed
		return nil
	})

	switch result {
	case nil:
		// success!
	case breaker.ErrBreakerOpen:
		// our function wasn't run because the breaker was open
	default:
		// some other error
	}
}