stateAndCooldown returns the key's state and remaining cooldown as a single atomic snapshot.
()
| 142 | // stateAndCooldown returns the key's state and remaining |
| 143 | // cooldown as a single atomic snapshot. |
| 144 | func (k *Key) stateAndCooldown() (KeyState, time.Duration) { |
| 145 | k.mu.RLock() |
| 146 | defer k.mu.RUnlock() |
| 147 | |
| 148 | if k.permanent { |
| 149 | return KeyStatePermanent, 0 |
| 150 | } |
| 151 | now := k.clock.Now() |
| 152 | if now.Before(k.cooldownUntil) { |
| 153 | return KeyStateTemporary, k.cooldownUntil.Sub(now) |
| 154 | } |
| 155 | return KeyStateValid, 0 |
| 156 | } |
| 157 | |
| 158 | // MarkTemporary marks the key as temporarily unavailable with |
| 159 | // the specified cooldown duration. Returns true if this call |