class will create a new (or use existing) lockfile locking it using an exclusive flock that automatically will release after the specified maxDurataionMs or when the unlock function is called. if the lock is not immediately available the class will wait up to the maxWaitDurationMs before throwing an exception

Ex:

// aftconfig.json
{
"fileLockMaxWait": 10000,
"fileLockMaxHold": 5000
}
// wait a maximum of 10 seconds to aquire lock and then hold
// lock for maximum of 5 seconds or until `unlock` is called
const lock = new ExpiringFileLock('unique_name');
try {
// perform action on shared resource...
} finally {
lock?.unlock();
}

Hierarchy

  • ExpiringFileLock

Constructors

Properties

_safeFlock: SafeFlock
_timeout: Timeout
aftCfg: AftConfig
lockDuration: number
lockName: string
waitDuration: number

Methods

  • creates a new ExpiringFileLock that can be used to ensure separate processes cannot cause a race condition when accessing a shared resource

    Parameters

    • name: string

      the name of the lock file

    • Optional wait: number

      the number of milliseconds to wait for a lock to be acquired

    • Optional hold: number

      the number of milliseconds that a lock can be held before it automatically releases

    Returns ExpiringFileLock

    an ExpiringFileLock instance

Generated using TypeDoc