Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrLockUnsuccessful = errors.New("store is locked") ErrUnlockUnsuccessful = errors.New("could not unlock store") )
Functions ¶
This section is empty.
Types ¶
type UnlockFunc ¶
type UnlockFunc func() error
UnlockFunc is the callback function returned by TryLock and TryRLock it should always be called inside a defer.
func TryLock ¶
TryLock acquires an exclusive advisory lock on a lock file.
If the file does not exist, it is created. If the lock cannot be acquired immediately, the function retries until the default timeout (100ms) is reached.
As a safeguard, the function attempts to recover from stale locks, defined as lock files older than 30 seconds. If recovery fails, manual intervention may be required.
It returns an unlock function that must be called to release the lock.
func TryRLock ¶
TryRLock acquires a non-exclusive advisory lock on a lock file.
If the file does not exist, it is created. If the lock cannot be acquired immediately, the function retries until the default timeout (100ms) is reached.
As a safeguard, the function attempts to recover from stale locks, defined as lock files older than 30 seconds. If recovery fails, manual intervention may be required.
It returns an unlock function that must be called to release the lock.