微服务如何保证不会出现连锁反应?Go 实现的断路器了解下( 四 )

<-tick:if h.config.Run() {h.count.Add(1)} else {h.count.Set(0)}case <-h.stopSignalCh:return}}}()}func (h *HealthCheck) stop() {h.mu.Lock()defer h.mu.Unlock()if !h.running {return}h.stopSignalCh <- struct{}{}h.running = falseh.count.Set(0)}func (h *HealthCheck) ok() bool {h.mu.Lock()defer h.mu.Unlock()if !h.running {return true}return h.count.Get() > h.config.Threshold && h.config.AllowProbability > rand.Intn(101)}func (h *HealthCheck) reset() {h.count.Set(0)}


推荐阅读