Function: withFileLock()
ts
function withFileLock<T>(
lockPath,
work,
options?
): Promise<T>;Defined in: with-file-lock.ts:18
Executes an asynchronous work callback while holding an exclusive file lock on lockPath.
Guarantees that the acquired FileLockLease is released inside a finally block even when work throws or rejects.
Type Parameters
| Type Parameter | Description |
|---|---|
T | Return value type of work. |
Parameters
| Parameter | Type | Description |
|---|---|---|
lockPath | string | Filesystem path of the lockfile to acquire. |
work | () => Promise<T> | Asynchronous critical-section callback to execute under the lock. |
options? | FileLockOptions | Optional timeout, stale threshold, heartbeat, and retry settings. |
Returns
Promise<T>
Result resolved by work.