flock

package
v1.32.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package flock implements a cross-platform file lock.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Flock

type Flock struct {
	// contains filtered or unexported fields
}

Flock is a cross-platform file lock. The zero value is not usable; use New to create a Flock.

func New

func New(path string) *Flock

New creates a new Flock for the given path. The lock file will be created if it does not exist.

func (*Flock) Lock

func (f *Flock) Lock(ctx context.Context) error

Lock acquires an exclusive lock, blocking until available or context is cancelled. Uses exponential backoff starting at 50ms up to 200ms between retries.

func (*Flock) Locked

func (f *Flock) Locked() bool

Locked returns whether this Flock instance holds the lock. Note: by the time you use the returned value, the state may have changed.

func (*Flock) Path

func (f *Flock) Path() string

Path returns the path to the lock file.

func (*Flock) TryLock

func (f *Flock) TryLock() (bool, error)

TryLock attempts to acquire an exclusive lock. Returns true if the lock was acquired, false if it is held by another process. Returns an error if the lock could not be attempted.

func (*Flock) Unlock

func (f *Flock) Unlock() error

Unlock releases the lock. Safe to call multiple times.

Jump to

Keyboard shortcuts

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