flock

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package flock wraps advisory whole-file locks. Two callers need them: the capture spool, which marks a segment live for as long as a writer holds it open (so recovery can tell "a call is in flight" from "a process died mid-call"), and the per-emitter monotonic counter, whose read-increment-write must be atomic across concurrent proxy processes sharing one state directory (Q48 — a duplicated counter would read as a gap that never happened).

Locks are per open file description, so they serialize between processes and between two handles in one process alike.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func With

func With(path string, fn func() error) error

With runs fn while holding an exclusive lock on path, creating the lock file if needed. It blocks until the lock is available.

Types

type Lock

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

Lock is a held advisory lock.

func Acquire

func Acquire(f *os.File) (*Lock, error)

Acquire takes an exclusive lock on f, blocking until it is available.

func TryLock

func TryLock(f *os.File) (*Lock, error)

TryLock takes an exclusive lock on f without blocking. It returns (nil, nil) when another holder has the lock — the caller's cue that the file is live.

func (*Lock) Release

func (l *Lock) Release()

Release drops the lock. Closing the file would also drop it; releasing explicitly keeps the lifetime obvious at the call site.

Jump to

Keyboard shortcuts

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