pub trait DistributedLock:
Send
+ Sync
+ 'static {
// Required methods
fn try_acquire<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 AdvisoryKey,
ttl: Duration,
) -> Pin<Box<dyn Future<Output = PersistenceResult<Option<LockGuard>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn acquire<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 AdvisoryKey,
ttl: Duration,
deadline: Duration,
) -> Pin<Box<dyn Future<Output = PersistenceResult<LockGuard>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn extend<'life0, 'life1, 'async_trait>(
&'life0 self,
guard: &'life1 LockGuard,
ttl: Duration,
) -> Pin<Box<dyn Future<Output = PersistenceResult<bool>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn release<'life0, 'async_trait>(
&'life0 self,
guard: LockGuard,
) -> Pin<Box<dyn Future<Output = PersistenceResult<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}Expand description
Acquire-then-release primitive over a distributed key.
Implementors are responsible for:
- exclusive acquisition by
key - per-acquire token issuance so
Self::releaseis idempotent even if the same key is held by a later attempt - TTL enforcement so a crashed holder doesn’t deadlock indefinitely
Cancellation: implementors honour the ambient cancellation token
propagated via entelix_core::ExecutionContext when one is in
scope. The trait itself does not take a context —
with_session_lock is the composition point.
Required Methods§
Sourcefn try_acquire<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 AdvisoryKey,
ttl: Duration,
) -> Pin<Box<dyn Future<Output = PersistenceResult<Option<LockGuard>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn try_acquire<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 AdvisoryKey,
ttl: Duration,
) -> Pin<Box<dyn Future<Output = PersistenceResult<Option<LockGuard>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Try once to acquire key with the given ttl. Returns
Ok(Some(guard)) on success, Ok(None) when the key is
currently held by another holder, and Err(_) for backend
failure.
Sourcefn acquire<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 AdvisoryKey,
ttl: Duration,
deadline: Duration,
) -> Pin<Box<dyn Future<Output = PersistenceResult<LockGuard>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn acquire<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 AdvisoryKey,
ttl: Duration,
deadline: Duration,
) -> Pin<Box<dyn Future<Output = PersistenceResult<LockGuard>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Block until the lock is acquired or deadline elapses.
Implementors poll with backoff between attempts.
Sourcefn extend<'life0, 'life1, 'async_trait>(
&'life0 self,
guard: &'life1 LockGuard,
ttl: Duration,
) -> Pin<Box<dyn Future<Output = PersistenceResult<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn extend<'life0, 'life1, 'async_trait>(
&'life0 self,
guard: &'life1 LockGuard,
ttl: Duration,
) -> Pin<Box<dyn Future<Output = PersistenceResult<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Extend the holder’s TTL. Returns Ok(false) when the lock has
already been released or expired (the guard’s token no longer
matches the stored value).
Sourcefn release<'life0, 'async_trait>(
&'life0 self,
guard: LockGuard,
) -> Pin<Box<dyn Future<Output = PersistenceResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn release<'life0, 'async_trait>(
&'life0 self,
guard: LockGuard,
) -> Pin<Box<dyn Future<Output = PersistenceResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Release the lock. Consumes the guard. The implementation is a no-op when the token already mismatches (lock expired by TTL before the caller got here).
Implementors§
impl DistributedLock for PostgresLock
postgres only.impl DistributedLock for RedisLock
redis only.