Struct CrossProcessLock
pub struct CrossProcessLock<L>{ /* private fields */ }Expand description
A cross-process lock implementation.
See the doc-comment of this module for more information.
Implementations§
§impl<L> CrossProcessLock<L>
impl<L> CrossProcessLock<L>
pub fn new(
locker: L,
lock_key: String,
lock_holder: String,
) -> CrossProcessLock<L>
pub fn new( locker: L, lock_key: String, lock_holder: String, ) -> CrossProcessLock<L>
Create a new cross-process lock.
§Parameters
lock_key: key in the key-value store to store the lock’s state.lock_holder: identify the lock’s holder with this given value.
pub fn is_dirty(&self) -> bool
pub fn is_dirty(&self) -> bool
Determine whether the cross-process lock is dirty.
See CrossProcessLockState::Dirty to learn more about the semantics
of dirty.
pub fn clear_dirty(&self)
pub fn clear_dirty(&self)
Clear the dirty state from this cross-process lock.
If the cross-process lock is dirtied, it will remain dirtied until this method is called. This allows recovering from a dirty state and marking that it has recovered.
pub async fn try_lock_once(
&self,
) -> Result<Result<CrossProcessLockState, CrossProcessLockUnobtained>, <L as TryLock>::LockError>
pub async fn try_lock_once( &self, ) -> Result<Result<CrossProcessLockState, CrossProcessLockUnobtained>, <L as TryLock>::LockError>
Try to lock once, returns whether the lock was obtained or not.
The lock can be obtained but it can be dirty. In all cases, the renew task will run in the background.
pub async fn spin_lock(
&self,
max_backoff: Option<u32>,
) -> Result<Result<CrossProcessLockState, CrossProcessLockUnobtained>, <L as TryLock>::LockError>
pub async fn spin_lock( &self, max_backoff: Option<u32>, ) -> Result<Result<CrossProcessLockState, CrossProcessLockUnobtained>, <L as TryLock>::LockError>
Attempt to take the lock, with exponential backoff if the lock has already been taken before.
The max_backoff parameter is the maximum time (in milliseconds) that
should be waited for, between two attempts. When that time is
reached a second time, the lock will stop attempting to get the lock
and will return a timeout error upon locking. If not provided,
will wait for MAX_BACKOFF_MS.
pub fn lock_holder(&self) -> &str
pub fn lock_holder(&self) -> &str
Returns the value in the database that represents the holder’s identifier.
Trait Implementations§
§impl<L> Clone for CrossProcessLock<L>
impl<L> Clone for CrossProcessLock<L>
§fn clone(&self) -> CrossProcessLock<L>
fn clone(&self) -> CrossProcessLock<L>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl<L> Freeze for CrossProcessLock<L>where
L: Freeze,
impl<L> !RefUnwindSafe for CrossProcessLock<L>
impl<L> Send for CrossProcessLock<L>
impl<L> Sync for CrossProcessLock<L>where
L: Sync,
impl<L> Unpin for CrossProcessLock<L>where
L: Unpin,
impl<L> !UnwindSafe for CrossProcessLock<L>
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,
§impl<T> CompatExt for T
impl<T> CompatExt for T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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>
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>
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