MCPcopy Index your code
hub / github.com/coder/coder / MarkTemporary

Method MarkTemporary

aibridge/keypool/keypool.go:161–186  ·  view source on GitHub ↗

MarkTemporary marks the key as temporarily unavailable with the specified cooldown duration. Returns true if this call transitions the key to temporary.

(cooldown time.Duration)

Source from the content-addressed store, hash-verified

159// the specified cooldown duration. Returns true if this call
160// transitions the key to temporary.
161func (k *Key) MarkTemporary(cooldown time.Duration) bool {
162 k.mu.Lock()
163 defer k.mu.Unlock()
164
165 // Permanent is irreversible.
166 if k.permanent {
167 return false
168 }
169
170 if cooldown <= 0 {
171 cooldown = defaultCooldown
172 }
173
174 now := k.clock.Now()
175 // Used to detect the valid -> temporary transition.
176 inCooldown := k.cooldownUntil.After(now)
177 newDeadline := now.Add(cooldown)
178
179 // In case the key has a later expiry, keep it.
180 if k.cooldownUntil.After(newDeadline) {
181 return false
182 }
183
184 k.cooldownUntil = newDeadline
185 return !inCooldown
186}
187
188// MarkPermanent marks the key as permanently unavailable. This
189// is a terminal state. Returns true if this call transitions

Callers 7

MarkKeyOnStatusFunction · 0.80
TestStateFunction · 0.80
TestMarkTemporaryFunction · 0.80
TestMarkPermanentFunction · 0.80
TestWalkerNextFunction · 0.80
TestKeyConcurrentFunction · 0.80
TestWalkerIndependenceFunction · 0.80

Calls 3

AddMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45

Tested by 6

TestStateFunction · 0.64
TestMarkTemporaryFunction · 0.64
TestMarkPermanentFunction · 0.64
TestWalkerNextFunction · 0.64
TestKeyConcurrentFunction · 0.64
TestWalkerIndependenceFunction · 0.64