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<bool, 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<bool, 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 acquire the lock.
  • If there was no previous lease, we will acquire the lock.
  • Otherwise, we don’t get the lock.

Returns whether taking the lock succeeded.

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§

Source§

impl TryLock for LockableCryptoStore

Source§

type LockError = CryptoStoreError

Source§

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

Implementors§