lease

package
v0.1.30 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 5 Imported by: 0 modules, 0 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

Overview

Package lease holds a process's claim on a file with flock: a process holds the exclusive lock for as long as it lives, and others probe it with a shared lock. The kernel drops the lock however the holder ends, so a probe never mistakes a dead holder, or a process that reused its PID, for a live one.

Index

Constants

This section is empty.

Variables

View Source
var ErrHeld = errors.New("the lease is held by another process")

ErrHeld says another process holds the lease.

Functions

func Hold

func Hold(path string, mode os.FileMode, wait time.Duration) (*os.File, error)

Hold opens path, creating it with mode, and takes its exclusive lock, retrying for up to wait so that a probe holding the shared lock for an instant does not read as a holder. The lease lasts until the returned file is closed or the process ends. The file itself is never removed: a process that opened it before a removal could otherwise lock a file no one else sees.

func Probe

func Probe(path string, whileFree func() error) (bool, error)

Probe reports whether another process holds the lease at path. A missing file is a lease no one holds. When no one holds it, whileFree, if set, runs while Probe holds the shared lock, so no holder can start meanwhile; its error is returned. Any other failure is returned rather than read as free.

func TryLock

func TryLock(file *os.File) error

TryLock takes the exclusive lock on file without waiting. It returns ErrHeld while another process holds it, and any other failure as it is.

Types

This section is empty.

Jump to

Keyboard shortcuts

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