Evan Huus ed2c12bb4a DRY up breaker.Go and breaker.Run 11 years ago
..
README.md b89f64cc19 Add build status to readmes 11 years ago
breaker.go ed2c12bb4a DRY up breaker.Go and breaker.Run 11 years ago
breaker_test.go 73049397fc Implement breaker.Go() 11 years ago

README.md

circuit-breaker

Build Status GoDoc

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
	}
}