flock

package
v0.42.0 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrLocked  = errors.New("locked")
	ErrTimeout = errors.New("lock timed out")
)

Functions

func Acquire

func Acquire(ctx context.Context, path, message string) (release func() error, err error)

Acquire a lock on the given path, storing the current PID and a message in the lock file.

The lock is released when the returned function is called.

If the lock is held by the current process, Acquire will return a no-op release function and the message WILL NOT be updated.

If the lock is held by another process, Acquire will block until the lock is released or the context is cancelled.

The file is NOT deleted on release; doing so creates a race condition that allows multiple processes to acquire the same lock.

Types

This section is empty.

Jump to

Keyboard shortcuts

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