Skip to content

l0.DependencyControl.FileLock

FileLock = require "l0.DependencyControl.FileLock"
local FileLock = require("l0.DependencyControl.FileLock")

FileLock

A cross-process advisory lock on a file. Usable as a cross-process lock primitive. Automatically released when the instance is garbage collected or when the process exits. However, unlike a semaphore, it cannot be forcibly taken from a process that is alive but hung.

Constructor

fileLock = FileLock path
local fileLock = FileLock(path)

Opens (creating if absent) the lock file and prepares it for locking.

param type description
path string Full path to the lock file.

Instance methods

tryLock

fileLock\tryLock!
fileLock:tryLock()

Attempts to acquire the lock without blocking.

Returns:

  • acquired boolean — True if acquired.

unlock

fileLock\unlock!
fileLock:unlock()

Releases the lock. Only the current holder should call this.

Returns:

  • issued boolean — True if a release was issued.

Fields

field type description
isAvailable boolean