Skip to content

Function: acquireFileLock() ​

ts
function acquireFileLock(lockPath, options?): Promise<FileLockLease>;

Defined in: acquire-file-lock.ts:25

Acquires an exclusive in-process (PQueue) and cross-process (open(..., 'wx') + heartbeat) lock on lockPath.

Serializes concurrent callers within the same Node.js process through a per-path PQueue({ concurrency: 1 }) while coordinating across external OS processes via atomic lockfile creation, periodic utimes heartbeats, and automatic stale/dead-PID reclamation.

Parameters ​

ParameterTypeDescription
lockPathstringFilesystem path of the lockfile to acquire.
options?FileLockOptionsOptional timeout, stale threshold, heartbeat, retry, and abort settings.

Returns ​

Promise<FileLockLease>

Active lock lease whose release() method frees both the disk lock and queue slot.

Throws ​

If lockPath is empty, options.signal is aborted while waiting, or the lock times out.

Released under the MIT License.