Skip to main content

LockableBackend

Trait LockableBackend 

Source
pub trait LockableBackend: Backend {
    // Required methods
    fn acquire_lock<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
        timeout_ms: u64,
    ) -> Pin<Box<dyn Future<Output = Result<Option<String>, BackendError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn release_lock<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
        lock_id: &'life2 str,
    ) -> Pin<Box<dyn Future<Output = Result<bool, BackendError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
}
Expand description

Optional extension for backends that support distributed locking.

Required Methods§

Source

fn acquire_lock<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, timeout_ms: u64, ) -> Pin<Box<dyn Future<Output = Result<Option<String>, BackendError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Acquire a distributed lock. Returns lock_id if acquired, None if contested.

Source

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

Release a distributed lock. Returns true if released. Must release only if lock_id still owns the lock: a late or duplicate release must never free a lock acquired since. Return Ok(false) when lock_id no longer owns the lock; Err only when the outcome is unknown. The single-flight takes Ok as answered and never re-sends it, and re-sends after an Err on the key’s next lock attempt.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§