Documentation ¶
Overview ¶
This file contains the Lock struct definition and its methods. Lock objects use channels to lock / unlock which allows for implementing a timeout when waiting to acquire a lock.
This file contains the Manager and ManagedLock struct definitions and methods along with their helper functions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidLockKey = errors.New("invalid lock key") ErrLockNotLocked = errors.New("lock is not locked") )
var ErrLockDoesNotExist = errors.New("a lock by that name does not exist")
Functions ¶
This section is empty.
Types ¶
type Lock ¶
type Lock struct {
// contains filtered or unexported fields
}
Lock represents a lock
func (*Lock) Lock ¶
Lock blocks until the lock is obtained or is canceled / timed out by context and returns a channel with the result. The interface returned will be either a struct{} (meaning the lock was acquired) or an error
type ManagedLock ¶
A ManagedLock is a lock with a some record keeping fields for garbage collection
func NewManagedLock ¶
func NewManagedLock(name string) *ManagedLock
NewManagedLock returns a managed lock object with the given name
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
A Manager polices access to a group of locks addressable by their names
func NewManager ¶
NewManager creates a new Manager with the given garbage collection interval, minimum idle time, and logger, and returns a pointer to the Manager.
Parameters: - gcInterval time.Duration: the interval for lock garbage collection - gcMinIdle time.Duration: the minimum time a lock must be idle before being considered for garbage collection Returns: - *Manager: a pointer to the newly created Manager - func(): a function that can be called to stop the Manager
func (*Manager) Lock ¶
Lock obtains a lock on the named lock. It blocks until a lock is obtained or is canceled / timed out by context