func (l *LeaderElection) stop() { log.Infoln("cleaning up") l.cleanupChannel <- struct{}{} l.stopChannel <- struct{}{} l.lock.Unlock() l.lock.Destroy() l.leader = false log.Infoln("cleanup done") }
func (l *LeaderElection) start() { clean := false for !clean { select { case <-l.cleanupChannel: clean = true default: log.Infoln("Running for leader election...") intChan, _ := l.lock.Lock(l.stopChannel) if intChan != nil { log.Infoln("Now acting as leader.") l.leader = true <-intChan l.leader = false log.Infoln("Lost leadership.") l.lock.Unlock() l.lock.Destroy() } } } }