Skip to main content

DistributedLocker

Trait DistributedLocker 

Source
pub trait DistributedLocker: Send + Sync {
    // Required methods
    fn acquire<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
        ttl: Duration,
        timeout: Timeout,
    ) -> Pin<Box<dyn Future<Output = Result<Option<String>>> + 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<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
}
Expand description

A cross-node lock backend.

Required Methods§

Source

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

Attempts to acquire the lock for key, waiting up to timeout.

Returns Some(token) on success (the token must be passed back to release), or None if the wait elapsed. ttl bounds how long the lock is held even if the holder dies.

§Errors

Returns an error only on backend failure, not on a normal timeout.

Source

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

Releases a previously-acquired lock. Releasing a token that is no longer held (e.g. it already expired) is a no-op, not an error.

§Errors

Returns an error only on backend failure.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§