pub struct WatchLock { /* private fields */ }Expand description
Advisory file lock for cross-process watch coordination.
The writer process acquires an exclusive lock, and reader processes can check whether a writer is active before polling for changes.
The lock is automatically released when this struct is dropped.
§Example
use pulsedb::WatchLock;
// Writer process
let lock = WatchLock::acquire_exclusive(&db_path)?;
// ... write experiences ...
drop(lock); // releases lock
// Reader process
if WatchLock::is_writer_active(&db_path) {
let seq = db.get_current_sequence()?;
let (events, _new_seq) = db.poll_changes(seq)?;
}Implementations§
Source§impl WatchLock
impl WatchLock
Sourcepub fn acquire_exclusive(db_path: &Path) -> Result<Self>
pub fn acquire_exclusive(db_path: &Path) -> Result<Self>
Acquires an exclusive lock (for the writer process).
Blocks until the lock is available. Only one exclusive lock can be held at a time.
§Errors
Returns an error if the lock file cannot be created or locked.
Acquires a shared lock (for reader processes).
Multiple shared locks can coexist. A shared lock blocks exclusive locks from being acquired.
§Errors
Returns an error if the lock file cannot be created or locked.
Sourcepub fn try_exclusive(db_path: &Path) -> Result<Option<Self>>
pub fn try_exclusive(db_path: &Path) -> Result<Option<Self>>
Tries to acquire an exclusive lock without blocking.
Returns Ok(Some(lock)) if acquired, Ok(None) if another
process holds the lock.
Sourcepub fn is_writer_active(db_path: &Path) -> bool
pub fn is_writer_active(db_path: &Path) -> bool
Checks whether a writer currently holds the exclusive lock.
This is a non-blocking check. Returns true if an exclusive lock
is held (writer is active), false otherwise.
Note: This has a TOCTOU race — the writer could start or stop between this check and any subsequent action. Use it as a hint, not a guarantee.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for WatchLock
impl RefUnwindSafe for WatchLock
impl Send for WatchLock
impl Sync for WatchLock
impl Unpin for WatchLock
impl UnsafeUnpin for WatchLock
impl UnwindSafe for WatchLock
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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