filelock

package
v1.223.1-rc.1 Latest Latest
Warning

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

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

Documentation

Overview

Package filelock provides cross-process advisory file locks for mutable files that are updated with a read-modify-write transaction.

Index

Constants

This section is empty.

Variables

View Source
var ErrAcquire = errors.New("file lock acquisition failed")

ErrAcquire indicates that a lock could not be acquired before the context was cancelled or its deadline elapsed.

Functions

This section is empty.

Types

type Lock

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

Lock is a cross-process advisory lock. Its path is deliberately stable and is never removed: callers normally use a sibling .lock file, which remains valid even when the protected file is atomically replaced.

func New

func New(path string) *Lock

New creates a lock backed by path. The path is usually the protected path with a .lock suffix.

func (*Lock) Path

func (l *Lock) Path() string

Path returns the lock file path.

func (*Lock) WithExclusive

func (l *Lock) WithExclusive(ctx context.Context, fn func() error) error

WithExclusive runs fn while holding an exclusive lock, or returns ErrAcquire when ctx finishes first. Locks are released even when fn returns an error.

func (*Lock) WithShared

func (l *Lock) WithShared(ctx context.Context, fn func() error) error

WithShared runs fn while holding a shared lock, or returns ErrAcquire when ctx finishes first.

Jump to

Keyboard shortcuts

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