Help us shape the future of Go! Take the 2026 Go Developer Survey

lock

package
v0.7.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Locker

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

Locker guards one file against other goroutines with an RWMutex, and against other processes with a lock file. Both spin on a try-lock, so neither is fair: a writer cannot preempt a steady stream of readers. The token cache relies on every holder releasing quickly, as a read is one field and a write is one token refresh. A holder of Lock may keep it for as long as a person takes, so whoever waits for such a lock gives up after a short timeout.

func New

func New(path string) Locker

func (Locker) Lock added in v0.3.0

func (l Locker) Lock(ctx context.Context) (unlock func() error, err error)

Lock holds the exclusive lock until unlock, which releases it on its first call only.

func (Locker) WithLock

func (l Locker) WithLock(ctx context.Context, fn func() error) error

func (Locker) WithRLock

func (l Locker) WithRLock(ctx context.Context, fn func() error) error

Jump to

Keyboard shortcuts

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