Skip to main content

DistributedLock

Trait DistributedLock 

Source
pub trait DistributedLock: Send + Sync {
    // Required methods
    fn acquire<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
        ttl: Duration,
    ) -> Pin<Box<dyn Future<Output = Result<Option<String>, LockError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn release<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
        token: &'life2 str,
    ) -> Pin<Box<dyn Future<Output = Result<(), LockError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
}
Expand description

Distributed lock abstraction.

acquire returns an ownership token that must be passed to release, so a lock can only be released by the process that holds it.

Required Methods§

Source

fn acquire<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, ttl: Duration, ) -> Pin<Box<dyn Future<Output = Result<Option<String>, LockError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Try to acquire the lock for key with the given ttl. Returns Some(token) on success, None if the lock is held by someone else.

Source

fn release<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, key: &'life1 str, token: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<(), LockError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Release the lock for key, but only if token still matches the holder.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§