pub trait LockHandle:
Send
+ Sync
+ Sized {
// Required methods
fn lost_token(&self) -> &Receiver<bool>;
fn release(self) -> impl Future<Output = LockResult<()>> + Send;
}Expand description
Handle to a held distributed lock.
Dropping this handle releases the lock. For proper error handling in async
contexts, call release() explicitly.
§Example
ⓘ
let handle = lock.acquire(None).await?;
// Critical section - we hold the lock
do_work().await;
// Explicit release with error handling
handle.release().await?;Required Methods§
Sourcefn lost_token(&self) -> &Receiver<bool>
fn lost_token(&self) -> &Receiver<bool>
Returns a receiver that signals when the lock is lost.
The receiver yields true when the lock is lost (e.g., connection died).
Not all backends support this; unsupported backends return a receiver
that never changes from false.
§Example
ⓘ
tokio::select! {
_ = handle.lost_token().changed() => {
eprintln!("Lock was lost!");
}
_ = do_work() => {
// Work completed while still holding lock
}
}Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.