Skip to main content

LockGuard

Struct LockGuard 

Source
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

Source

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.

Source

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.

Source

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.

Source

pub async fn is_still_held(&self) -> Result<bool>

Whether we still hold it.

Source

pub fn owner(&self) -> &str

The random token identifying this holder.

Source

pub fn key(&self) -> &str

The cache key.

Trait Implementations§

Source§

impl Debug for LockGuard

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for LockGuard

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more