FileLock class

A lock implementation using files to prevent concurrent execution.

This class provides a way to synchronize access to resources between different processes. It uses the file system to create and manage locks.

Note: This implementation relies on file system operations for locking, which may have performance implications depending on the underlying storage.

Constructors

FileLock(FileStore store, String name, int seconds, [String? lockOwner])
A lock implementation using files to prevent concurrent execution.

Properties

hashCode int
The hash code for this object.
no setterinherited
lockOwner String?
An identifier for the lock owner, used to ensure only the owner can release the lock.
final
name String
The name of the lock.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
seconds int
The duration for which the lock is valid, in seconds.
final
store FileStore
The underlying FileStore used to manage the lock file.
final

Methods

acquire() Future<bool>
Attempts to acquire the lock by creating a lock file.
block(int seconds, [Function? callback]) Future
Blocks execution until the lock can be acquired, or the timeout is reached.
forceRelease() → void
Forces the release of the lock, regardless of ownership.
get([Function? callback]) Future
Executes a callback while holding the lock, ensuring the lock is released afterwards.
getCurrentOwner() Future<String?>
Retrieves the identifier of the current lock owner.
isOwnedByCurrentProcess() Future<bool>
Checks if the current process owns the lock.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
owner() Future<String>
Returns the current owner of the lock.
release() Future<bool>
Releases the lock by deleting the lock file, but only if this instance owns the lock.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited