Created
October 25, 2021 06:53
-
-
Save mayankshah1607/21f0b01f46025a67908dd63df540e805 to your computer and use it in GitHub Desktop.
Run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Run starts the leader election loop. Run will not return | |
// before leader election loop is stopped by ctx or it has | |
// stopped holding the leader lease | |
func (le *LeaderElector) Run(ctx context.Context) { | |
defer runtime.HandleCrash() | |
defer func() { | |
le.config.Callbacks.OnStoppedLeading() | |
}() | |
if !le.acquire(ctx) { | |
return // ctx signalled done | |
} | |
ctx, cancel := context.WithCancel(ctx) | |
defer cancel() | |
go le.config.Callbacks.OnStartedLeading(ctx) | |
le.renew(ctx) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment