You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When the OnStateChange method is trigered, I want to know the breaker counts, so i call breaker.Counts(), but I get a deadlock
The code is :
OnStateChange: func(name string, from gobreaker.State, to gobreaker.State) {
// NOTICE:do not call breaker.Counts() in this method , it will cause a deadlock !!!
counts := breaker.Counts()
logger.Infof("key: %s, breaker state has change, from %s to %s , the data --> %v", breaker.Name(), from.String(), to.String(), counts)
}
What method should I call when I want to know the counts number in OnStateChange method ?
The text was updated successfully, but these errors were encountered:
1.creating a goroutine where a channel receive change and call breaker.Counts().
I think the above way is better:
type StateChange struct {
Name string
From gobreaker.State
To gobreaker.State
Counts gobreaker.Counts
}
ch := make(chan *StateChange)
var cb *gobreaker.CircuitBreaker
st := gobreaker.Settings{
OnStateChange: func(name string, from gobreaker.State, to gobreaker.State) {
go func(name string, from gobreaker.State, to gobreaker.State) {
ch <- &StateChange{
Name: name,
From: from,
To: to,
Counts: cb.Counts(),
}
}(name, from, to)
},
}
cb = gobreaker.NewCircuitBreaker(st)
When the OnStateChange method is trigered, I want to know the breaker counts, so i call breaker.Counts(), but I get a deadlock
The code is :
What method should I call when I want to know the counts number in OnStateChange method ?
The text was updated successfully, but these errors were encountered: