flock

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: MIT Imports: 7 Imported by: 1 module, 8 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Meta added in v1.1.0

type Meta struct {
	At        time.Time `json:"at"`
	PID       int       `json:"pid"`
	Intent    string    `json:"intent"`
	SessionID string    `json:"session_id"`
}

type T

type T struct {
	locker.Locker
	Path string
	// contains filtered or unexported fields
}

T wraps flock and dumps JSON data in the lock file hinting about what holds the lock.

func New

func New(p string, sessionId string, lockP func(string) locker.Locker) *T

New allocate a file lock struct from the Locker provider.

func (*T) Lock

func (t *T) Lock(timeout time.Duration, intent string) (err error)

Lock acquires an exclusive file lock on the file and writes a JSON formatted structure hinting who holds the lock and with what intention.

func (*T) Probe added in v1.1.0

func (t *T) Probe() (Meta, error)

Probe attempts to acquire a file lock. If successful, it releases the lock and returns an empty Meta. If the lock is already held by another process, it reads and returns the current lock metadata. Note: Reading the metadata may fail if the other process has not finished writing it.

func (*T) UnLock

func (t *T) UnLock() error

UnLock releases the file lock acquired by Lock, and empties the lock file of its holder.

The lock file is kept, not removed: a lock is one of the file, not of its path, and a process opening the file before its removal would lock it once released, while another one creates a new file at the path and locks it, both holding the lock.

The file of the Locker is closed, and a new Locker replaces it: a lock is one of the process on the file, released when any of its descriptors of the file closes, and the file of a Locker unlocked but left open, closed later as it is collected, would release the lock of another Locker of the process holding it.

Jump to

Keyboard shortcuts

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