Run starts the leader election loop
(ctx context.Context)
| 188 | |
| 189 | // Run starts the leader election loop |
| 190 | func (le *LeaderElector) Run(ctx context.Context) { |
| 191 | defer func() { |
| 192 | runtime.HandleCrash() |
| 193 | le.config.Callbacks.OnStoppedLeading() |
| 194 | }() |
| 195 | if !le.acquire(ctx) { |
| 196 | return // ctx signalled done |
| 197 | } |
| 198 | ctx, cancel := context.WithCancel(ctx) |
| 199 | defer cancel() |
| 200 | go le.config.Callbacks.OnStartedLeading(ctx) |
| 201 | le.renew(ctx) |
| 202 | } |
| 203 | |
| 204 | // RunOrDie starts a client with the provided config or panics if the config |
| 205 | // fails to validate. |