GetBreaker need double-check (#112)

master
shenbaise9527 4 years ago committed by GitHub
parent 0ce654968d
commit 9e9ce3bf48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -41,10 +41,12 @@ func GetBreaker(name string) Breaker {
} }
lock.Lock() lock.Lock()
defer lock.Unlock() b, ok = breakers[name]
if !ok {
b = NewBreaker() b = NewBreaker(WithName(name))
breakers[name] = b breakers[name] = b
}
lock.Unlock()
return b return b
} }
@ -55,20 +57,5 @@ func NoBreakFor(name string) {
} }
func do(name string, execute func(b Breaker) error) error { func do(name string, execute func(b Breaker) error) error {
lock.RLock() return execute(GetBreaker(name))
b, ok := breakers[name]
lock.RUnlock()
if ok {
return execute(b)
}
lock.Lock()
b, ok = breakers[name]
if !ok {
b = NewBreaker(WithName(name))
breakers[name] = b
}
lock.Unlock()
return execute(b)
} }

Loading…
Cancel
Save