Skip to main content

LockManager

Trait LockManager 

Source
pub trait LockManager:
    Send
    + Sync
    + Debug {
    // Required method
    fn try_lock<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Option<Box<dyn LockGuard>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided method
    fn lock<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
        timeout: Duration,
    ) -> Pin<Box<dyn Future<Output = Result<Box<dyn LockGuard>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

Acquire and release named locks.

Implementations only need to provide try_lock; the default lock polls it under a tokio::time::timeout.

Required Methods§

Source

fn try_lock<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, ) -> Pin<Box<dyn Future<Output = Option<Box<dyn LockGuard>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Try to acquire the named lock without waiting. Returns None if it is already held, the key is rejected by [validate_key], or the backend cannot acquire the lock for any other reason.

Provided Methods§

Source

fn lock<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, timeout: Duration, ) -> Pin<Box<dyn Future<Output = Result<Box<dyn LockGuard>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Acquire the named lock, polling try_lock until it succeeds or timeout elapses.

timeout is mandatory to make accidental deadlocks impossible at the API level. Pass Duration::MAX if you really want to wait indefinitely.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§