InterProcessLock class
A cross-process, cross-isolate advisory lock backed by an atomically
created lock file (O_CREAT | O_EXCL).
Unlike RandomAccessFile.lock, whose POSIX advisory locks are owned per
process (so several isolates in one process all acquire the "exclusive"
lock), the lock file's existence is the lock, owned by whoever creates it
first. It therefore serializes separate processes and sibling isolates
uniformly - the case that matters when dart test runs suites as isolates
sharing one process.
An abandoned lock is reclaimed per StaleLockPolicy. The file holds a unique per-acquisition token, so reclaim and release only ever delete the lock they actually hold, never one a different acquirer has since taken.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
release(
) → Future< void> - Releases the lock. Safe to call more than once. Only removes the file if it still holds our token, so a lock another acquirer has since reclaimed is never deleted out from under them.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
acquire(
String path, {required StaleLockPolicy staleWhen, Duration timeout = const Duration(minutes: 6), Duration pollInterval = const Duration(milliseconds: 50), Duration maxPollInterval = const Duration(seconds: 1), Duration? heartbeatInterval}) → Future< InterProcessLock> -
Acquires the lock at
path, blocking until it is held. -
withLock<
T> (String path, Future< T> action(), {required StaleLockPolicy staleWhen, Duration timeout = const Duration(minutes: 6), Duration pollInterval = const Duration(milliseconds: 50), Duration maxPollInterval = const Duration(seconds: 1), Duration? heartbeatInterval}) → Future<T> -
Acquires the lock at
path, runsaction, and releases it afterwards (even ifactionthrows). See acquire for the parameters.