locking

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FSLockGroup

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

FSLockGroup is a Group implementation that uses filesystem locks for mutual exclusion. It uses the gofrs/flock library to ensure only one execution happens for a given key at a time across all goroutines and processes. Unlike SingleflightGroup, this does not share results within the same process - each caller will execute the function once they acquire the lock.

func NewFlockGroup

func NewFlockGroup(lockDir string) (*FSLockGroup, error)

NewFlockGroup creates a new FlockGroup. lockDir is the directory where lock files will be created. If lockDir is empty, it defaults to os.TempDir()/gobuildcache-locks.

func (*FSLockGroup) DoWithLock

func (g *FSLockGroup) DoWithLock(key string, fn func() (interface{}, error)) (v interface{}, err error)

Do executes and returns the results of the given function using filesystem locks. Only one execution will occur for a given key at a time across all processes. The shared return value is always false since this implementation provides mutual exclusion rather than result sharing.

type Group

type Group interface {
	// DoWithLock runs the given function with mutual exclusion over the given key.
	DoWithLock(key string, fn func() (interface{}, error)) (v interface{}, err error)
}

locking.Group is an abstraction for running functions with mutual exclusion over sets of keys.

type MemLock

type MemLock struct {
	sync.Mutex
	// contains filtered or unexported fields
}

MemLock is a Group implementation that uses in-memory locks (mutexes) for mutual exclusuion. It only works within a single gobuildcache process and doesn't work if there are multiple gobuildcache processes running concurrently on the same filesystem. It's used primarily in tests.

func NewMemLock

func NewMemLock() *MemLock

func (*MemLock) DoWithLock

func (s *MemLock) DoWithLock(key string, fn func() (interface{}, error)) (v interface{}, err error)

type NoOpGroup

type NoOpGroup struct{}

NoOpGroup is a Group implementation that performs no locking. Every call executes the function immediately. This is useful for testing or scenarios where locking is not needed.

func NewNoOpGroup

func NewNoOpGroup() *NoOpGroup

NewNoOpGroup creates a new NoOpGroup.

func (*NoOpGroup) DoWithLock

func (n *NoOpGroup) DoWithLock(key string, fn func() (interface{}, error)) (v interface{}, err error)

Jump to

Keyboard shortcuts

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