TryLock

Trait TryLock 

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<u64>, Self::LockError>> + SendOutsideWasm;
}
Expand description

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

Required Associated Types§

Required Methods§

fn try_lock( &self, lease_duration_ms: u32, key: &str, holder: &str, ) -> impl Future<Output = Result<Option<u64>, 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", so this trait is not object safe.

Implementations on Foreign Types§

§

impl TryLock for LockableCryptoStore

§

type LockError = CryptoStoreError

§

async fn try_lock( &self, lease_duration_ms: u32, key: &str, holder: &str, ) -> Result<Option<u64>, <LockableCryptoStore as TryLock>::LockError>

Implementors§