Skip to content

Instantly share code, notes, and snippets.

@mayankshah1607
Created October 25, 2021 06:53
Show Gist options
  • Save mayankshah1607/21f0b01f46025a67908dd63df540e805 to your computer and use it in GitHub Desktop.
Save mayankshah1607/21f0b01f46025a67908dd63df540e805 to your computer and use it in GitHub Desktop.
Run
// 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