pub struct LockGuard { /* private fields */ }Expand description
A held lock.
§This does not release on drop
Releasing means a round trip to the cache, and Drop cannot await. The
options were a blocking call inside Drop (which deadlocks a single-threaded
runtime), spawning a task (which needs a runtime handle that may be shutting
down), or being explicit.
Explicit, then — with the TTL as the safety net. A guard that is dropped
without release holds its lock until it expires, which is
late rather than forever. Prefer Lock::run, which cannot forget.
Implementations§
Source§impl LockGuard
impl LockGuard
Sourcepub async fn release(self) -> Result<bool>
pub async fn release(self) -> Result<bool>
Release it. true if it was still ours to release.
false means the TTL expired while we were working and somebody else
has since taken it — so the work overran, and two copies have been
running. Worth logging where it matters; it is the signal that the TTL
is too short.
Sourcepub async fn extend(&self, ttl: Duration) -> Result<bool>
pub async fn extend(&self, ttl: Duration) -> Result<bool>
Push the expiry out to ttl from now. true if it was still ours.
For work that is still going and does not know how long it has left. A
false here is the same bad news as from release, and arrives early
enough to abandon the work rather than finish it alongside a second
copy.
Implemented as a re-put rather than a bare EXPIRE, so it works on
every driver — including the ones with no separate expiry command.
Sourcepub fn keep(self)
pub fn keep(self)
Give up the guard without releasing the lock, so it stands until the TTL expires.
Deliberate abandonment, not a leak — and distinct from dropping the guard, which logs a warning on the assumption you forgot.
The case it exists for is a claim that has to outlive the work: the
scheduler’s on_one_server takes a lock for the current minute so the
other machines find it taken, and releasing it when the run finishes
would let a machine whose clock is a second behind claim the same
minute and run it again.
Sourcepub async fn is_still_held(&self) -> Result<bool>
pub async fn is_still_held(&self) -> Result<bool>
Whether we still hold it.