Skip to main content

TryLock

Trait TryLock 

Source
pub trait TryLock {
    type LockError: Error + Send + Sync;

    // Required method
    fn try_lock(
        &self,
        lease_duration_ms: u32,
        key: &str,
        holder: &str,
    ) -> impl Future<Output = Result<Option<CrossProcessLockGeneration>, Self::LockError>> + SendOutsideWasm;
}
Expand description

Trait used to try to take a lock. Foundation of CrossProcessLock.

Required Associated Types§

Required Methods§

Source

fn try_lock( &self, lease_duration_ms: u32, key: &str, holder: &str, ) -> impl Future<Output = Result<Option<CrossProcessLockGeneration>, Self::LockError>> + SendOutsideWasm

Try to take a leased lock.

This attempts to take a lock for the given lease duration.

  • If we already had the lease, this will extend the lease.
  • If we didn’t, but the previous lease has expired, we will obtain the lock.
  • If there was no previous lease, we will obtain the lock.
  • Otherwise, we don’t get the lock.

Returns Some(_) to indicate the lock succeeded, None otherwise. The cross-process lock generation must be compared to the generation before the call to see if the lock has been dirtied: a different generation means the lock has been dirtied, i.e. taken by a different holder in the meantime.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§