// Run periodically calls to announce presence,
// should be called explicitly in a separate goroutine
Run periodically calls to announce presence,
should be called explicitly in a separate goroutine
// Run periodically calls to announce presence // should be called explicitly in a separate goroutine
func (h *Heartbeat) Run() error {
	defer func() {
		h.reset(HeartbeatStateInit)
		h.checkTicker.Stop()
	}()
	for {
		err := h.fetchAndAnnounce()
		if err != nil {
			h.Warningf("Heartbeat failed %v.", err)
		}
		h.OnHeartbeat(err)
		select {
		case <-h.checkTicker.C:
		case <-h.sendC:
			h.Debugf("Asked check out of cycle")
		case <-h.cancelCtx.Done():
			h.Debugf("Heartbeat exited.")
			return nil
		}
	}
}
func ( h * Heartbeat ) Run ( ) error { defer func ( ) { h . reset ( HeartbeatStateInit ) h . checkTicker . Stop ( ) } ( ) for { err := h . fetchAndAnnounce ( ) if err != nil { h . Warningf ( " " , err ) } h . OnHeartbeat ( err ) select { case <- h . checkTicker . C : case <- h . sendC : h . Debugf ( " " ) case <- h . cancelCtx . Done ( ) : h . Debugf ( " " ) return nil } } }
Run periodically calls to announce presence,
should be called explicitly in a separate goroutine
Run periodically calls to announce presence should be called explicitly in a separate goroutine