pub struct LockRegistry {
inner: Mutex<RegistryInner>,
}Expand description
Thread-safe in-memory registry of active resource locks.
Wrap in Arc<LockRegistry> and manage via Tauri’s state system.
Fields§
§inner: Mutex<RegistryInner>Implementations§
Source§impl LockRegistry
impl LockRegistry
pub fn new() -> Self
Sourcepub fn acquire(
&self,
scope: LockScope,
op_name: impl Into<String>,
ttl_secs: u64,
now: i64,
) -> Result<LockId, AppError>
pub fn acquire( &self, scope: LockScope, op_name: impl Into<String>, ttl_secs: u64, now: i64, ) -> Result<LockId, AppError>
Acquire a lock for scope / op_name with ttl_secs TTL.
Returns the new LockId on success. Returns AppError::Locked when
any existing lock has an intersecting scope.
The caller is responsible for emitting lock:acquired via
lifecycle::emit_acquired.
Sourcepub fn heartbeat(&self, lock_id: &LockId, now: i64) -> Result<(), AppError>
pub fn heartbeat(&self, lock_id: &LockId, now: i64) -> Result<(), AppError>
Extend the heartbeat for lock_id.
Returns AppError::NotFound if the lock does not exist.
Sourcepub fn release(&self, lock_id: &LockId) -> Result<ResourceLock, AppError>
pub fn release(&self, lock_id: &LockId) -> Result<ResourceLock, AppError>
Release a lock explicitly.
Returns AppError::NotFound if the lock does not exist.
The returned ResourceLock carries the scope needed for the event.
Sourcepub fn list(&self, scope_filter: Option<&LockScope>) -> Vec<ResourceLock>
pub fn list(&self, scope_filter: Option<&LockScope>) -> Vec<ResourceLock>
Return all active locks, optionally filtered to those whose scope
intersects scope_filter.
Sourcepub fn release_stale(&self, now: i64) -> Vec<ResourceLock>
pub fn release_stale(&self, now: i64) -> Vec<ResourceLock>
Release all locks whose TTL has expired relative to now.
Returns the released locks so the caller can emit events.
Sourcepub fn startup_cleanup(&self) -> Vec<ResourceLock>
pub fn startup_cleanup(&self) -> Vec<ResourceLock>
Remove all locks regardless of TTL.
Called once at app start to clear any locks left over from a prior crash
or abnormal exit. Returns the removed locks so the caller can emit
lock:released { reason: StartupCleanup } for each.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for LockRegistry
impl RefUnwindSafe for LockRegistry
impl Send for LockRegistry
impl Sync for LockRegistry
impl Unpin for LockRegistry
impl UnsafeUnpin for LockRegistry
impl UnwindSafe for LockRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more