FileLock
Defined in: packages/app-system/src/async/file-lock.ts:38
A simple file-based lock mechanism.
Creates a .lock file to indicate that a resource is locked. The lock is
acquired by creating the lock file and released by deleting it. If the lock
file already exists, it means the resource is locked by another process.
Example usage:
const lock = new LockFile("/path/to/resource");const release = await lock.acquire();try { // Do something with the locked resource} finally { await release();}Implements
Section titled “Implements”ILock
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new FileLock(
filePath,options?):FileLock
Defined in: packages/app-system/src/async/file-lock.ts:42
Parameters
Section titled “Parameters”filePath
Section titled “filePath”string
options?
Section titled “options?”Returns
Section titled “Returns”FileLock
Properties
Section titled “Properties”filePath
Section titled “filePath”
readonlyfilePath:string
Defined in: packages/app-system/src/async/file-lock.ts:43
Accessors
Section titled “Accessors”locked
Section titled “locked”Get Signature
Section titled “Get Signature”get locked():
boolean
Defined in: packages/app-system/src/async/file-lock.ts:49
Indicates whether the lock is currently held.
Returns
Section titled “Returns”boolean
Implementation of
Section titled “Implementation of”ILock.locked
Methods
Section titled “Methods”lock()
Section titled “lock()”lock(
signal?):Promise<void>
Defined in: packages/app-system/src/async/file-lock.ts:67
Acquires the lock, waiting if necessary until it is available.
Parameters
Section titled “Parameters”signal?
Section titled “signal?”AbortSignal | null
An optional AbortSignal to cancel the acquire operation.
Returns
Section titled “Returns”Promise<void>
A promise that resolves when the lock is acquired.
Implementation of
Section titled “Implementation of”ILock.lock
tryLock()
Section titled “tryLock()”tryLock():
Promise<boolean>
Defined in: packages/app-system/src/async/file-lock.ts:53
Attempts to acquire the lock without waiting.
Returns
Section titled “Returns”Promise<boolean>
True if the lock was successfully acquired, false otherwise.
Implementation of
Section titled “Implementation of”ILock.tryLock
unlock()
Section titled “unlock()”unlock():
Promise<void>
Defined in: packages/app-system/src/async/file-lock.ts:74
Releases the lock.
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”ILock.unlock