scheduleCleanupLocked resets (or starts) the cleanup timer so it fires at the earliest pending checker-expiration deadline among all currently idle, unheld checkers. Must be called with p.mu held. Must NOT be called on discarded pools.
()
| 394 | // unheld checkers. |
| 395 | // Must be called with p.mu held. Must NOT be called on discarded pools. |
| 396 | func (p *checkerPool) scheduleCleanupLocked() { |
| 397 | var earliestDeadline time.Time |
| 398 | for i := range p.checkers { |
| 399 | if p.checkers[i] == nil || p.heldBy[i] != "" || p.lastReleased[i].IsZero() { |
| 400 | continue |
| 401 | } |
| 402 | deadline := p.lastReleased[i].Add(p.opts.IdleTimeout) |
| 403 | if earliestDeadline.IsZero() || deadline.Before(earliestDeadline) { |
| 404 | earliestDeadline = deadline |
| 405 | } |
| 406 | } |
| 407 | if earliestDeadline.IsZero() { |
| 408 | // No idle checkers remain — stop the timer if it exists. |
| 409 | if p.cleanupTimer != nil { |
| 410 | p.cleanupTimer.Stop() |
| 411 | p.cleanupTimer = nil |
| 412 | } |
| 413 | return |
| 414 | } |
| 415 | delay := time.Until(earliestDeadline) |
| 416 | if delay <= 0 { |
| 417 | delay = time.Millisecond |
| 418 | } |
| 419 | if p.cleanupTimer != nil { |
| 420 | p.cleanupTimer.Reset(delay) |
| 421 | } else { |
| 422 | p.cleanupTimer = time.AfterFunc(delay, p.cleanupIdleCheckers) |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | // cleanupIdleCheckers disposes checkers that have been idle for longer than |
| 427 | // the idle timeout. The API checker is separate and never idle-cleaned. |
no test coverage detected