flock

package
v0.0.22 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func TryLock(ctx context.Context, root *os.Root) (UnlockFunc, error)

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

func TryRLock(ctx context.Context, root *os.Root) (UnlockFunc, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL