Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename the return function as afterRequestCallback for Allow method #45

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions gobreaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,31 +245,31 @@ func (cb *CircuitBreaker) Execute(req func() (interface{}, error)) (interface{},
}

// Name returns the name of the TwoStepCircuitBreaker.
func (tscb *TwoStepCircuitBreaker) Name() string {
return tscb.cb.Name()
func (breaker *TwoStepCircuitBreaker) Name() string {
return breaker.cb.Name()
}

// State returns the current state of the TwoStepCircuitBreaker.
func (tscb *TwoStepCircuitBreaker) State() State {
return tscb.cb.State()
func (breaker *TwoStepCircuitBreaker) State() State {
return breaker.cb.State()
}

// Counts returns internal counters
func (tscb *TwoStepCircuitBreaker) Counts() Counts {
return tscb.cb.Counts()
func (breaker *TwoStepCircuitBreaker) Counts() Counts {
return breaker.cb.Counts()
}

// Allow checks if a new request can proceed. It returns a callback that should be used to
// register the success or failure in a separate step. If the circuit breaker doesn't allow
// requests, it returns an error.
func (tscb *TwoStepCircuitBreaker) Allow() (done func(success bool), err error) {
generation, err := tscb.cb.beforeRequest()
func (breaker *TwoStepCircuitBreaker) Allow() (afterRequestCallback func(success bool), err error) {
generation, err := breaker.cb.beforeRequest()
if err != nil {
return nil, err
}

return func(success bool) {
tscb.cb.afterRequest(generation, success)
breaker.cb.afterRequest(generation, success)
}, nil
}

Expand Down
8 changes: 4 additions & 4 deletions gobreaker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ func succeedLater(cb *CircuitBreaker, delay time.Duration) <-chan error {
}

func succeed2Step(cb *TwoStepCircuitBreaker) error {
done, err := cb.Allow()
afterRequestCallback, err := cb.Allow()
if err != nil {
return err
}

done(true)
afterRequestCallback(true)
return nil
}

Expand All @@ -63,12 +63,12 @@ func fail(cb *CircuitBreaker) error {
}

func fail2Step(cb *TwoStepCircuitBreaker) error {
done, err := cb.Allow()
afterRequestCallback, err := cb.Allow()
if err != nil {
return err
}

done(false)
afterRequestCallback(false)
return nil
}

Expand Down
Loading