pub struct DistributedLock { /* private fields */ }Expand description
Lock factory. Cheap to clone.
Implementations§
Source§impl DistributedLock
impl DistributedLock
pub fn new(cache: BoxedCache) -> Self
Sourcepub async fn try_acquire(&self, name: &str, ttl: Duration) -> Option<LockGuard>
pub async fn try_acquire(&self, name: &str, ttl: Duration) -> Option<LockGuard>
Try to acquire name for ttl. Returns:
Some(LockGuard)when we got it. Callrelease()when done (drop without release leaves the lock to expire on TTL — safe but slightly wasteful of contention slots).Nonewhen someone else holds it.
Sourcepub async fn with_lock<F, Fut, R>(
&self,
name: &str,
ttl: Duration,
body: F,
) -> Option<R>
pub async fn with_lock<F, Fut, R>( &self, name: &str, ttl: Duration, body: F, ) -> Option<R>
Acquire-or-skip helper: runs body only if we got the lock.
Returns Some(R) when body ran, None when another holder
blocked us. The lock is released after body finishes (or on
panic, via the guard’s Drop — which is best-effort since we
can’t call async fns from Drop).
Trait Implementations§
Source§impl Clone for DistributedLock
impl Clone for DistributedLock
Source§fn clone(&self) -> DistributedLock
fn clone(&self) -> DistributedLock
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for DistributedLock
impl !RefUnwindSafe for DistributedLock
impl Send for DistributedLock
impl Sync for DistributedLock
impl Unpin for DistributedLock
impl UnsafeUnpin for DistributedLock
impl !UnwindSafe for DistributedLock
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more