pub struct LockManager { /* private fields */ }
Expand description
A lock manager to create “managed” locks.
Managed lock’s lifecycle is managed by the lock manager background thread, that includes: - Automatic lease refresh - Lock revocation when the lock is dropped
You can clone LockManager
to share it across threads, it is really cheap to do so.
See spawn_lock_manager
to create a new lock manager.
Implementations§
Source§impl LockManager
impl LockManager
Sourcepub async fn try_lock<S>(
&self,
name: S,
lease_duration: Duration,
) -> Result<ManagedLock, TryLockError>
pub async fn try_lock<S>( &self, name: S, lease_duration: Duration, ) -> Result<ManagedLock, TryLockError>
Tries to lock a key with automatic lease refresh and lock revocation when dropped.
If the key is already held by another lock, it will return an error immediately.
Sourcepub async fn try_lock_with_lease<S>(
&self,
name: S,
managed_lease: ManagedLease,
) -> Result<ManagedLock, TryLockError>
pub async fn try_lock_with_lease<S>( &self, name: S, managed_lease: ManagedLease, ) -> Result<ManagedLock, TryLockError>
Similar to LockManager::try_lock
but with a custom lease.
Sourcepub async fn lock<S>(
&self,
name: S,
lease_duration: Duration,
) -> Result<ManagedLock, Error>
pub async fn lock<S>( &self, name: S, lease_duration: Duration, ) -> Result<ManagedLock, Error>
Locks a key with automatic lease refresh and lock revocation when dropped. If the key is already held by another lock, it will wait until the lock is released.
Be aware this method can await indefinitely if the key is never released.
Sourcepub async fn lock_with_lease<S>(
&self,
name: S,
managed_lease: ManagedLease,
) -> Result<ManagedLock, Error>
pub async fn lock_with_lease<S>( &self, name: S, managed_lease: ManagedLease, ) -> Result<ManagedLock, Error>
Similar to LockManager::lock
but with a custom lease.
Trait Implementations§
Source§impl Clone for LockManager
impl Clone for LockManager
Source§fn clone(&self) -> LockManager
fn clone(&self) -> LockManager
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl !Freeze for LockManager
impl !RefUnwindSafe for LockManager
impl Send for LockManager
impl Sync for LockManager
impl Unpin for LockManager
impl !UnwindSafe for LockManager
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
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request