Skip to content

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();
}
  • ILock

new FileLock(filePath, options?): FileLock

Defined in: packages/app-system/src/async/file-lock.ts:42

string

FileLockOptions

FileLock

readonly filePath: string

Defined in: packages/app-system/src/async/file-lock.ts:43

get locked(): boolean

Defined in: packages/app-system/src/async/file-lock.ts:49

Indicates whether the lock is currently held.

boolean

ILock.locked

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.

AbortSignal | null

An optional AbortSignal to cancel the acquire operation.

Promise<void>

A promise that resolves when the lock is acquired.

ILock.lock


tryLock(): Promise<boolean>

Defined in: packages/app-system/src/async/file-lock.ts:53

Attempts to acquire the lock without waiting.

Promise<boolean>

True if the lock was successfully acquired, false otherwise.

ILock.tryLock


unlock(): Promise<void>

Defined in: packages/app-system/src/async/file-lock.ts:74

Releases the lock.

Promise<void>

ILock.unlock