(ctx context.Context)
| 373 | } |
| 374 | |
| 375 | func (n *Node) IsReady(ctx context.Context) bool { |
| 376 | tries := 0 |
| 377 | for { |
| 378 | select { |
| 379 | case <-n.shutdown: |
| 380 | return false |
| 381 | case <-time.After(200 * time.Millisecond): |
| 382 | // wait for the leader to be elected |
| 383 | if n.GetRaftLead() != raft.None { |
| 384 | return true |
| 385 | } |
| 386 | |
| 387 | tries++ |
| 388 | if tries >= 10 { |
| 389 | // waiting too long, just return the running status |
| 390 | n.logger.Warn("Leader not elected, return the running status") |
| 391 | return n.isRunning.Load() |
| 392 | } |
| 393 | case <-ctx.Done(): |
| 394 | return false |
| 395 | } |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | func (n *Node) LeaderChange() <-chan bool { |
| 400 | return n.leaderChanged |
nothing calls this directly
no test coverage detected