WaitForSession waits until a session is available or context is cancelled
(ctx context.Context)
| 380 | |
| 381 | // WaitForSession waits until a session is available or context is cancelled |
| 382 | func (cm *ConnManager) WaitForSession(ctx context.Context) (*Session, error) { |
| 383 | ticker := time.NewTicker(100 * time.Millisecond) |
| 384 | defer ticker.Stop() |
| 385 | |
| 386 | for { |
| 387 | select { |
| 388 | case <-ctx.Done(): |
| 389 | return nil, ctx.Err() |
| 390 | case <-ticker.C: |
| 391 | if session := cm.GetCurrent(); session != nil { |
| 392 | return session, nil |
| 393 | } |
| 394 | } |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | // IsHealthy returns whether the session is healthy |
| 399 | func (s *Session) IsHealthy() bool { |