DbFileLock class
Best-effort cross-process advisory lock on a JSON database file.
We don't lock the data file directly because Dart's atomic
writeAsString re-creates the file, which would invalidate any open
handle / lock. Instead we lock a sidecar <path>.lock file. Any
other process that opens the same database via this library will see
the lock and either wait or fail, depending on which acquire flavour
it uses.
In addition to the OS-level lock we keep an in-process set of
already-held lock paths so a single process opening the same
database twice gets a fast StateError instead of a deadlock on
itself (the OS lock is per-process on most platforms and would
otherwise be re-entrant silently).
Constructors
- DbFileLock(String path)
Properties
Methods
-
acquire(
{bool exclusive = true}) → Future< void> -
Acquire a lock, blocking until granted. By default takes an
exclusive lock; pass
exclusive: falsefor a shared (reader) lock. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
release(
) → Future< void> - Release the lock. Safe to call when nothing was acquired.
-
toString(
) → String -
A string representation of this object.
inherited
-
tryAcquire(
{bool exclusive = true}) → Future< bool> - Try to acquire without blocking. Returns true on success, false if another process currently holds it.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited