Home > @rushstack/node-core-library > LockFile > acquire

LockFile.acquire() method

Attempts to create the lockfile. Will continue to loop at every 100ms until the lock becomes available or the maxWaitMs is surpassed.

Signature:

static acquire(resourceFolder: string, resourceName: string, maxWaitMs?: number): Promise<LockFile>;

Parameters

Parameter Type Description
resourceFolder string The folder where the lock file will be created
resourceName string An alphanumeric name that describes the resource being locked. This will become the filename of the temporary file created to manage the lock.
maxWaitMs number The maximum number of milliseconds to wait for the lock before reporting an error

Returns:

Promise<LockFile>

Remarks

This function is subject to starvation, whereby it does not ensure that the process that has been waiting the longest to acquire the lock will get it first. This means that a process could theoretically wait for the lock forever, while other processes skipped it in line and acquired the lock first.