Synchronizes access to a shared file for multiple concurrent processes.

Constructors

Properties

file: File
lock: FileHandle

Accessors

Methods

  • Asynchronously append the given contents to this lock file.

    It is unsafe to call appendFile() multiple times on the same file without waiting for the Promise to be resolved (or rejected).

    Parameters

    • data: string | ArrayBufferView
    • Optionalencoding: Encoding

    Returns Promise<void>

  • Asynchronously writes the given contents to this lock file, replacing any old contents.

    It is unsafe to call writeFile() multiple times on the same file without waiting for the Promise to be resolved (or rejected).

    Parameters

    • data: string | ArrayBufferView
    • Optionalencoding: Encoding

    Returns Promise<void>

  • Checks if the given file is locked.

    Parameters

    • name: string | File

      Name of the file to check.

    • options: LockFileOptions = {}

      Lock file options.

    Returns Promise<"unlocked" | "locked" | "stale">

    Lock status, one of "unlocked" "locked" or "stale".

  • Attempts to lock the given file. Throws [[LockFileError]] if file cannot be locked.

    Parameters

    • name: string | File

      Name of the file to lock.

    • options: LockFileOptions & RetryOptions

      Lock file options.

    Returns Promise<LockFile>

    A promise which resolves with [[LockFile]] instance on success.

  • Executes the given callback function after locking the given file. Throws [[LockFileError]] if file cannot be locked.

    Type Parameters

    • T

    Parameters

    • name: string | File

      Name of the file to lock.

    • options: LockFileOptions & RetryOptions

      Lock file options.

    • callback: ((lock: LockFile) => Promise<T>)

      A callback to executes once the file is locked.

        • (lock): Promise<T>
        • Parameters

          Returns Promise<T>

    Returns Promise<T>

    The result of the callback.