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") )
Functions ¶
This section is empty.
Types ¶
type Lock ¶
type Lock struct {
// contains filtered or unexported fields
}
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, ctx context.Context, size int32) *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 ¶
func NewManager(shards uint32, gcInterval time.Duration, gcMinIdle time.Duration) (*Manager, func())
NewManager creates a new Manager with the given garbage collection interval, minimum idle time, and logger, and returns a pointer to the Manager.
Parameters:
- ctx context.Context: the context for the Manager
- shards uint32: the number of lock shards to use
- 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 (*Manager) Lock ¶
func (m *Manager) Lock(name string, key string, size int32, ctx context.Context) (<-chan interface{}, error)
Lock obtains a lock on the named lock. It blocks until a lock is obtained or is canceled or timed out by context