pub trait Lock: Send + Sync {
// Required methods
fn lock(&self) -> impl Future<Output = Result<(), LockError>> + Send + '_;
fn try_lock(
&self,
) -> impl Future<Output = Result<bool, LockError>> + Send + '_;
fn unlock(&self) -> impl Future<Output = Result<(), LockError>> + Send + '_;
}Expand description
A single lock instance whose operations yield to the executor instead of blocking the OS thread.
Every operation is asynchronous because a lock may be backed by I/O: the
in-memory lock resolves immediately, but a durable lock (e.g. the SQLx
lease-table PostgresLock /
SqliteLock) acquires and releases by talking to the
database. lock awaits until the lock becomes free; try_lock attempts a
single non-blocking acquire; unlock releases the lock and (for in-memory)
wakes any waiters so they can re-contend.
All returned futures are Send so an async QueuedRepository built on this
lock keeps its repository futures Send (required by the async repo traits).
Required Methods§
Sourcefn lock(&self) -> impl Future<Output = Result<(), LockError>> + Send + '_
fn lock(&self) -> impl Future<Output = Result<(), LockError>> + Send + '_
Acquire the lock, awaiting until it becomes available.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".