A resource locker making use of the proper-lockfile library. Note that no locks are kept in memory, thus this is considered thread- and process-safe.

This proper-lockfile library has its own retry mechanism for the operations, since a lock/unlock call will either resolve successfully or reject immediately with the causing error. The retry function of the library however will be ignored and replaced by our own LockUtils' retryFunction function.

Hierarchy

  • FileSystemResourceLocker

Implements

Constructors

Properties

attemptSettings: Required<AttemptSettings>
finalized: boolean = false
lockFolder: string

Folder that stores the locks

lockOptions: LockOptions
logger: Logger = ...

Methods

  • This function is used to override the proper-lock onCompromised function. Once the locker was finalized, it will log the provided error instead of throwing it This allows for a clean shutdown procedure.

    Parameters

    • err: any

    Returns void

  • Generate LockOptions or UnlockOptions depending on the type of defauls given. A custom lockFilePath mapping strategy will be used.

    Returns

    LockOptions or UnlockOptions

    Type Parameters

    • T

    Parameters

    • identifier: ResourceIdentifier

      ResourceIdentifier to generate (Un)LockOptions for

    • defaults: T

      The default options. (lockFilePath will get overwritten)

    Returns T

  • Releases a lock on the requested identifier. The promise will resolve when the lock has been released. In case there is no lock on the resource an error should be thrown.

    Parameters

    Returns Promise<void>

  • Wrapper function for all (un)lock operations. Any errors coming from the fn() will be swallowed. Only ENOTACQUIRED errors wills be thrown (trying to release lock that didn't exist). This wrapper returns undefined because retryFunction expects that when a retry needs to happen.

    Returns

    Boolean or undefined.

    Parameters

    • fn: (() => Promise<unknown>)

      The function reference to swallow errors from.

        • (): Promise<unknown>
        • Returns Promise<unknown>

    Returns (() => Promise<unknown>)

      • (): Promise<unknown>
      • Wrapper function for all (un)lock operations. Any errors coming from the fn() will be swallowed. Only ENOTACQUIRED errors wills be thrown (trying to release lock that didn't exist). This wrapper returns undefined because retryFunction expects that when a retry needs to happen.

        Returns

        Boolean or undefined.

        Returns Promise<unknown>